承接 jabarihunt/password 相关项目开发

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

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

jabarihunt/password

Composer 安装命令:

composer require jabarihunt/password

包简介

Simple Password class.

README 文档

README

This is a simple class that uses the standard PHP methods password_hash() and password_verify() to create a hashed password and compare the hash to entered passwords respectively. The primary purpose of this class is to remove some of the boilerplate code required when performing these password operations.

The class defaults to using the default algorithm that PHP selects (per version) and a cost of 10. Both can be set when creating the hash.

NOTE: It is recommended that database columns that store hashes created with password_hash() are at least 255 characters wide, as the length of hashes will grow in future versions of PHP!

INSTALLING

Via Composer

Run the following command in the same directory as your composer.json file:

php composer.phar require jabarihunt/password

Via Github

  1. Clone this repository into a working directory: git clone git@github.com:jabarihunt/password .

  2. Include the Password class in your project...

require('/path/to/Password.php')

...or if using an auto-loader...

 use jabarihunt/Password;

USAGE

The Password::create() and Password::compare() methods will throw exceptions if invalid data is passed to them, so be sure to use try/catch blocks!

Creating Password Hashes

<?php

    $password = 'FooBar1@';
    
    try {
        $hash1 = Password::create($password);                       // basic usage
        $hash2 = Password::create($password, PASSWORD_BCRYPT);      // set algorithm
        $hash3 = Password::create($password, PASSWORD_BCRYPT, 12);  // set algorithm & cost
    } catch (\Exception $e) {
        var_dump($e);
    }
    
    echo "hash1: {$hash1} <br/> hash2: {$hash2} <br/> hash3: $hash3}";

?>
/* OUTPUT*/
hash1: $2y$10$lqfDbrxDEwnw34uaJCBN4OLatL3XKWnxuIwBTHqhcY5NVvvljlnd6 
hash2: $2y$10$2b2nHGE1Jx58AyHxVwWiq.EC039DNB9HLzcY.3b7tpEdIvLg6j30q 
hash3: $2y$12$e284Os/7zD4MsxXFX9h5UuKj3disIkmOkIJRzj4CnMoT3np7tyD2y

Comparing Passwords And Hashes

Using our first hash from above...

<?php

    $password = 'FooBar1@';
    $hash     = '$2y$10$lqfDbrxDEwnw34uaJCBN4OLatL3XKWnxuIwBTHqhcY5NVvvljlnd6';
    
    try {
        $passwordIsValid = Password::compare($password, $hash);  // returns boolean
        var_dump($passwordIsValid);
    }
    catch (\Exception $e) {
        var_dump($e);
    }

?>
/* OUTPUT*/
/var/www/html/controllers/HomeController.php:7:boolean true

Validating Passwords

There is a third method, Password::isValid(), that validates if a password follows the below rules and returns a boolean. Eventually I'll add functionallity to pass your own rules. This method doesn't throw any exceptiones.

Password Rules:

  • Is not empty
  • Contains at least 8 charatcters
  • Contains at least 1 uppercase letter
  • Contains at least 1 lowercase letter
  • Contains at least 1 number
  • Contains at least 1 symbol

You can optionally pass a second string parameter called $username that will make sure the password does not contain the username (or whatever the passed string contains).

<?php

    $username = 'Foo';

    $password1 = 'FooBar';
    $password2 = 'FooBar1@';

    var_dump(Password::isValid($password1));
    var_dump(Password::isValid($password2));
    var_dump(Password::isValid($password2, $username));

?>
/* OUTPUT*/
/var/www/html/controllers/HomeController.php:8:boolean false
/var/www/html/controllers/HomeController.php:9:boolean true
/var/www/html/controllers/HomeController.php:10:boolean false

CONTRIBUTING

  1. Fork Repository
  2. Create a descriptive branch name
  3. Make edits to your branch
  4. Squash (rebase) your commits
  5. Create a pull request

LICENSE

This project is licensed under the MIT License - see the LICENSE.md file for details

jabarihunt/password 适用场景与选型建议

jabarihunt/password 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「password」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jabarihunt/password 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jabarihunt/password 我们能提供哪些服务?
定制开发 / 二次开发

基于 jabarihunt/password 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-07