- <?php
- class Fremnet_Security_SSHA1 {
- private $saltLen;
- public function __construct($saltLen = 10) {
- $this->saltLen = $saltLen;
- }
- public function hash($subject) {
- return $this->_hash($subject);
- }
- public function compare($hash,$subject) {
- return ($this->_hash($subject,$hash) === $hash);
- }
- private function generateSalt($saltLen = null) {
- if ($saltLen === null)
- $saltLen = $this->saltLen;
- $salt = '';
- while (strlen($salt) < $saltLen) {
- $salt = substr(sha1(uniqid(rand(), true)).$salt,0,$saltLen);
- }
- return $salt;
- }
- private function _hash($subject,$salt = null) {
- if ($salt === null) {
- $salt = $this->generateSalt();
- } else {
- $salt = substr($salt, 0, $this->saltLen);
- }
- return $salt . sha1($salt . $subject);
- }
- }
Posted by Anonymous on Fri 5th Jan 08:15
download | new post
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.