rafaelgou/php-apache2-basic-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rafaelgou/php-apache2-basic-auth

Composer 安装命令:

composer create-project rafaelgou/php-apache2-basic-auth

包简介

PHP Apache2 Basic Auth

README 文档

README

A really simple class service for .htaccess Basic Auth using .htpasswd and .htgroups files.

Original HtPasswd and HtGroup classes from Yang Yang

If you want a running app using this lib, see PHP Apache2 Basic Auth Manager

Full API

See API

Installation

This standard can be installed with the Composer dependency manager.

  1. Install Composer
  2. Install the coding standard as a dependency of your project
composer require rafaelgou/php-apache2-basic-auth

Using

You need to define a .htpasswd file and a optionally a .htgroups file.

Instanciate the Service

<?php

// ...
use Apache2BasicAuth\Service as HTService;

$htService = new HTService(
    'PATH_TO/.htpasswd',
    'PATH_TO/.htgroups'
);

Creating a Group

<?php

// ... Instanciate the Service ...

// Create a new group
$group = $htService->createGroup();
$group->setName('admin')
    ->addUser('mateus')
    ->addUser('tiago');

// Groups can be also set:
$group->setUsers(array('bernardo', 'larissa'));

// Staging to write    
$htService->persist($group);

// Writing to disc
$htService->write();

Editing a Group

<?php

// ... Instanciate the Service ...

// Create a new group
$group = $htService->findGroup('admin');
$group
    ->removeUser('mateus')
    ->addUser('ana');

// Staging to write    
$htService->persist($group);

// Writing to disc
$htService->write();

Deleting a Group

<?php

// ... Instanciate the Service ...

// Create a new group
$group = $htService->findGroup('admin');

// Staging to write    
$htService->htService->removeGroup($group);

// Writing to disc
$htService->write();

Creating a User

<?php

// ... Instanciate the Service ...

// Create a new user
$user = $htService->createUser();
$user->setUsername('rafael')
    ->setPassword('my_pass_123')
    ->setAddGroup('admin')
    ->setAddGroup('finance');

// Groups can be also set:
$user->setGroups(array('opperations', 'support'));

// Staging to write    
$htService->persist($user);

// Writing to disc
$htService->write();

OBS: When you set a password the hashed password is updated.

Editing a user

<?php

// ... Instanciate the Service ...

// Finding an existing user
$user = $htService->findUser('rafael');
$user->setPassword('my_pass_123')
    ->removeGroup('admin')
    ->setAddGroup('marketing');

// Staging to write    
$htService->persist($user);

// Writing to disc
$htService->write();

OBS: When you set a password the hashed password is updated. If not set, old hash is kept.

Deleting a user

<?php

// ... Instanciate the Service ...

// Finding an existing user
$user = $htService->findUser('rafael');

// Staging to write    
$htService->htService->removeUser($user);

// Writing to disc
$htService->write();

Listing Groups and Users

<?php

// ... Instanciate the Service ...

// Getting Users
$users = $htService->getUsers();

// The key is the username too
foreach ($users as $username => $user) {
    echo $user->getUsername();
    echo $user->getHash(); // Hashed password
    echo implode(', ', $user->getGroups());
}

// Getting Groups
$groups = $htService->getGroups();

// The key is the username too
foreach ($groups as $groupname => $group) {
    echo $group->getName();
    echo implode(', ', $user->getUsers());
}

统计信息

  • 总下载量: 363
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固