承接 nichdu/simple-auth 相关项目开发

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

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

nichdu/simple-auth

最新稳定版本:v0.2.0

Composer 安装命令:

composer require nichdu/simple-auth

包简介

library for simple single user authentication via secret, random and time stamp

README 文档

README

Build Status

This is a simple PHP authentication library if you don't want to mess around with user names and passwords.

Usage

Here is a basic usage example:

<?php

require '/path/to/SimpleRoute/src/autoload.php';

$a = new SimpleRoute\Authenticator('verysecret');

// to create a hash to send to a server
$date = new DateTime;
$random = 'veryrandom';
$hash = $a->createAuthentication($random, $date);

// to check a received hash against the secret
$isValid = $a->authenticate($date, $random, $hash);

Setting parameters

Parameter Method Explanation
Hash algorithm setHashAlgorithm (instance method) Setting the hash algorithm for hash creation and validation. The algorithm must be in hash_algos().
Default hash algorithm setDefaultHashAlgorithm (class method) Setting the default hash algorithm.
Hash rounds setHashRounds (instance method) Setting the number of hash rounds (log 2).
Default hash rounds setDefaultHashRounds (class method) Setting the default number of hash rounds (log 2).
Time difference setTimeDifference (instance method) Setting the maximum time difference between creation of the authentication hash and its validation. If the time difference is longer than this value the authentication hash will be rejected. Keep in mind that people could have slow internet connections and wrong system clocks which can influence the hash's time.
Default time difference setDefaultTimeDifference (class method) Setting the default maximum time difference between creation of the authentication hash and its validation. See above for more information.

Please note that all default methods will only influence future instances of Authenticator. Existing ones will keep their current values.

How does it work?

To create your own authentication hash, you must do the following:

  1. Use the same secret as the server
  2. Generate a random string
  3. Get the current date and time and format as string formatted according to PHP's c-format (ISO 8601)
  4. Concatenate the random string, the date string, and the secret (in this order, without seperators)
  5. Run the hash function you set the set number of times (e.g. in default settings: run sha-256 2^10 times.
  6. The result is the authentication hash.

Todos

  • none, currently

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-4-Clause
  • 更新时间: 2015-05-11