承接 dmitrymomot/php-auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dmitrymomot/php-auth

Composer 安装命令:

composer require dmitrymomot/php-auth

包简介

PHP Auth

README 文档

README

Simply authentication library

Key points:

  • Supports drivers ('file' and 'database' adapters already included in the package).
  • Easy to use
  • Minimum configuration

Installation

This package is available via Composer:

{
    "require": {
        "dmitrymomot/php-auth": "1.*"
    }
}

Example of usage

Usage adapter File

$auth = new \Auth\Adapter\File;
$auth->setUsers(array('test_user' => array('password' => 'hashed_password', 'role' => 'user')));

Log in

$auth->login('test_user', 'password'); // returns boolean value

Get user

$auth->getUser('guest') // returns current username or 'guest', if user isn't logged in

Get user role

$auth->getRole() // returns string

Check log in

$auth->loggedIn() // returned true

Check log in as

$auth->loggedIn('admin') // returned false
$auth->loggedIn('user') // returned true

Log out

$auth->logout(); // returns boolean value

Log in as another user

$auth->loginAs('username'); // returns boolean value

Come back to initial user

$auth->comeBack(); // returns boolean value

Usage adapter Database

(supports all the same that 'file' adapter)

In composer.json add package php-activerecord/php-activerecord

    "require": {
		"dmitrymomot/php-session": "1.*",
        "php-activerecord/php-activerecord":"dev-master"
    },

and update composer.

Set database config (read more in php-activerecord docs)

$cfg = \ActiveRecord\Config::instance();
$cfg->set_connections(array(
	'development' => 'mysql://username_for_dev:password@localhost/username_for_dev',
	'production' => 'mysql://username:password@localhost/database_name'
));

Initialization

$auth = new \Auth\Adapter\Database();

Initialization with custom model User

class CustomUser implements \Auth\Model\UserInterface {
	//....realisation of interface
}

$model = '\Custom\Model\CustomUser'; // full path to class
$auth = new \Auth\Adapter\Database($model);

Get user

$auth->getUser('guest') // returns instance of class \Auth\Model\User or 'guest', if user isn't logged in

Create new user

$auth->createUser(array('username' => 'test_user', 'password' => 'some_password', 'email' => 'user@mail.com', ...)); // returns boolean value or array error messages

Update current user

$auth->updateUser(array('username' => 'test_user', 'password' => 'some_password', ....)); // returns boolean value or array error messages

Helpers

echo \Auth\Auth::hash('admin'); // returns hashed string 'admin'

Also you can set hash key

\Auth\Auth::hashKey = 'vv34r3v4c34r';

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固