当前位置: 首页>>代码示例>>PHP>>正文


PHP crypt函数代码示例

本文整理汇总了PHP中crypt函数的典型用法代码示例。如果您正苦于以下问题:PHP crypt函数的具体用法?PHP crypt怎么用?PHP crypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了crypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkPasswordForUser

 public static function checkPasswordForUser($password, UserEntity $user)
 {
     if (hash_equals($user->getPassword(), crypt($password, $user->getPassword()))) {
         return true;
     }
     return false;
 }
开发者ID:paulstoica,项目名称:sgbd,代码行数:7,代码来源:Security.php

示例2: login

 public function login($username, $password)
 {
     # Check dependencies
     self::dependencies(isset($this->settings, $username, $password));
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     # Check login with MD5 hash
     if ($username === $this->settings['username'] && $password === $this->settings['password']) {
         $_SESSION['login'] = true;
         return true;
     }
     # Check login with crypted hash
     if ($username === $this->settings['username'] && $this->settings['password'] === crypt($password, $this->settings['password'])) {
         $_SESSION['login'] = true;
         return true;
     }
     # No login
     if ($this->settings['username'] === '' && $this->settings['password'] === '') {
         $_SESSION['login'] = true;
         return true;
     }
     # Call plugins
     $this->plugins(__METHOD__, 1, func_get_args());
     return false;
 }
开发者ID:neynah,项目名称:Lychee,代码行数:25,代码来源:Session.php

示例3: addUser

    public function addUser()
    {
        $username = $this->input->post('username');
        $query = 'INSERT INTO users (username, name, email, password, created_at, updated_at)
	          				  VALUES(?, ?, ?, ? ,NOW(), NOW())';
        return $this->db->query($query, array($username, $this->input->post('name'), $this->input->post('email'), crypt($this->input->post('pword'), "SecretSaltyGoodness23")));
    }
开发者ID:To-mos,项目名称:trakit,代码行数:7,代码来源:user.php

示例4: guardar

 public function guardar()
 {
     $arrayprivilegios = $this->input->post('privilegios');
     $usuario = new Usuario($this->input->post('idusuario'));
     $password = $this->input->post('password');
     if ($usuario->exists()) {
         if (!empty($password)) {
             $usuario->password = crypt($password, 'mr%fsdfOk5ad');
         }
     } else {
         $usuario->password = crypt($password, 'mr%fsdfOk5ad');
     }
     $usuario->usuario = $this->input->post('usuario');
     $usuario->email = $this->input->post('email');
     $usuario->save();
     //guardamos los privilegios...
     $privilegios = new Privilegio();
     $privilegios->get();
     $usuario->delete($privilegios->all);
     //borramos todos...
     foreach ($arrayprivilegios as $idprivilegio) {
         $privilegio = new Privilegio($idprivilegio);
         $usuario->save($privilegio);
     }
     redirect('admin/usuarios/listado');
 }
开发者ID:visionclick,项目名称:testcv,代码行数:26,代码来源:usuarios.php

示例5: ADODB_Session_Key

 function ADODB_Session_Key()
 {
     $ADODB_CRYPT_KEY = 'CRYPTED ADODB SESSIONS ROCK!';
     /* USE THIS FUNCTION TO CREATE THE ENCRYPTION KEY FOR CRYPTED SESSIONS	*/
     /* Crypt the used key, $ADODB_CRYPT_KEY as key and session_ID as SALT	*/
     return crypt($ADODB_CRYPT_KEY, session_ID());
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:7,代码来源:adodb-cryptsession.php

示例6: authenticate

 /**
  * @param string $secret
  * @param int $code
  * @return bool
  */
 public function authenticate($secret, $code)
 {
     $correct = false;
     for ($i = -1; $i <= 1; $i++) {
         if ($this->calculateCode($secret) == $code) {
             $correct = true;
             break;
         }
     }
     // If they're not using a cache to prevent people being able to use the same code twice or if they were wrong anyway...
     if (!isset($this->cachePool) || $correct == false) {
         return $correct;
     }
     // If we're here then we must be using a cache, and we must be right
     // We generate the key as securely as possible, then salt it using something that will always be replicatable.
     // We're doing this hashing for de-duplication (aka, we want to know if it exists), but as we're also possibly
     // securing the secret somewhere, we want to try and have as secure as possible
     //
     // If someone has any better suggestions on how to achieve this, please send in a PR! :P
     $key = crypt($secret . "|" . $code, md5($code));
     // If it existed, then we want this function to return false
     if ($this->cachePool->hasItem($key)) {
         return false;
     }
     // If it didn't, then we want this function to add it to the cache
     // In PSR-6 getItem will always contain an CacheItemInterface and that seems to be the only way to add stuff
     // to the cachePool
     $item = $this->cachePool->getItem($key);
     // It's a quick expiry thing, 30 seconds is more than long enough
     $item->expiresAfter(new \DateInterval("PT30S"));
     // We don't care about the value at all, it's just something that's needed to use the caching interface
     $item->set(true);
     $this->cachePool->save($item);
     return true;
 }
开发者ID:dolondro,项目名称:google-authenticator,代码行数:40,代码来源:GoogleAuthenticator.php

示例7: hash_pwd

function hash_pwd($pwd)
{
    $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
    $salt = sprintf("\$2a\$%02d\$", 10) . $salt;
    $hash = crypt($pwd, $salt);
    return $hash;
}
开发者ID:peter279k,项目名称:water_sports103,代码行数:7,代码来源:insert_data.php

示例8: check

 public static function check($input, $stored_hash)
 {
     if (version_compare(PHP_VERSION, '5.3') < 0) {
         throw new Exception("Bcrypt requires PHP 5.3 or above");
     }
     return crypt($input, $stored_hash) == $stored_hash;
 }
开发者ID:pombredanne,项目名称:vulnDB,代码行数:7,代码来源:bcrypt.php

示例9: encrypt

 /**
  * Encrypt value
  *
  * @param string $value
  * @param string $salt   Salt or crypted hash
  * @return string
  */
 public function encrypt($value, $salt = null)
 {
     if ($value instanceof Fs_File) {
         $value = $value->getContents();
     }
     $value .= $this->secret;
     switch (strtolower($this->method)) {
         case null:
         case 'crypt':
             return crypt($value, $salt);
         case 'std_des':
             if (!CRYPT_STD_DES) {
                 throw new Exception("Unable to encrypt value: Standard DES-based encryption with crypt() not available.");
             }
             return crypt($value, isset($salt) ? substr($salt, 0, 2) : $this->makesalt(2));
             break;
         case 'ext_des':
             if (!CRYPT_EXT_DES) {
                 throw new Exception("Unable to encrypt value: Extended DES-based encryption with crypt() not available.");
             }
             return crypt($value, isset($salt) ? $salt : $this->makesalt(9));
         case 'md5':
             if (!CRYPT_MD5) {
                 throw new Exception("Unable to encrypt value: MD5 encryption with crypt() not available.");
             }
             return crypt($value, isset($salt) ? $salt : $this->makesalt(12));
         case 'blowfish':
             if (!CRYPT_BLOWFISH) {
                 throw new Exception("Unable to encrypt value: Blowfish encryption with crypt() not available.");
             }
             return crypt($value, isset($salt) ? $salt : $this->makesalt(29));
         default:
             throw new Exception("Unable to encrypt value: Unknown crypt method '{$this->method}'");
     }
 }
开发者ID:jasny,项目名称:Q,代码行数:42,代码来源:System.php

示例10: isValidUser

 public function isValidUser($userName, $password)
 {
     $user = $this->getByUsername($userName);
     if (is_null($user)) {
         return null;
     }
     $savedPassword = $user->getField($this->getUserTable()->password);
     $validatedUser = null;
     if ($savedPassword === AUTH_PASSWORD_NOT_CACHED) {
         return null;
     }
     if ($this->passwordIsLegacyHash($savedPassword)) {
         if ($savedPassword === md5($password . $this->_siteSalt) || $savedPassword === md5($password) || $savedPassword === md5(addslashes($password) . $this->_siteSalt) || $savedPassword === md5(addslashes($password))) {
             $validatedUser = $user;
         }
     } else {
         if (!function_exists('crypt')) {
             throw new ErrorException("Crypt must be loaded for password_verify to function");
         }
         $ret = crypt($password, $savedPassword);
         if (!is_string($ret) || strlen($ret) != strlen($savedPassword) || strlen($ret) <= 13) {
             return null;
         }
         $status = 0;
         $lenRet = strlen($ret);
         for ($i = 0; $i < $lenRet; $i++) {
             $status |= ord($ret[$i]) ^ ord($savedPassword[$i]);
         }
         if ($status === 0) {
             $validatedUser = $user;
         }
     }
     return $validatedUser;
 }
开发者ID:byjg,项目名称:authuser,代码行数:34,代码来源:UsersMoodleDataset.php

示例11: verify

 public static function verify($str, $hash)
 {
     if ($hash == crypt($str, $hash)) {
         return true;
     }
     return false;
 }
开发者ID:askoxyz,项目名称:elsa,代码行数:7,代码来源:Hash.php

示例12: authenticate

 /**
  * Authenticates the password with the users current password.
  *
  * @param string $password
  *
  * @return boolean
  */
 public function authenticate($password)
 {
     if ($this->password_ver == 'crypt') {
         return $this->password === crypt($password, $this->password);
     } else {
     }
 }
开发者ID:dasklney,项目名称:traq,代码行数:14,代码来源:User.php

示例13: validate

 public function validate($strPlainText, $strHash)
 {
     if (CRYPT_SHA512 != 1) {
         throw new Exception('Hashing mechanism not supported.');
     }
     return crypt($strPlainText, $strHash) == $strHash ? true : false;
 }
开发者ID:alikh31,项目名称:FeedCloud,代码行数:7,代码来源:UserIdentity.php

示例14: encrypt

 /**
  * Encrypts the data
  * @param string $data
  * @return string
  * @throws \InvalidArgumentException
  * @see hash()
  */
 public function encrypt($data)
 {
     if (!is_string($data)) {
         throw new \InvalidArgumentException('data');
     }
     return crypt($data, $this->getSalt());
 }
开发者ID:nyclagniappe,项目名称:phpjazz,代码行数:14,代码来源:Crypt.php

示例15: authenticate

function authenticate($username, $password)
{
    $encrypted_old = md5($password);
    $row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username), true);
    if ($row['username'] && $row['username'] == $username) {
        // Migrate from old, unhashed password
        if ($row['password'] == $encrypted_old) {
            $row_type = dbFetchRow('DESCRIBE users password');
            if ($row_type['Type'] == 'varchar(34)') {
                changepassword($username, $password);
            }
            return 1;
        } else {
            if (substr($row['password'], 0, 3) == '$1$') {
                $row_type = dbFetchRow('DESCRIBE users password');
                if ($row_type['Type'] == 'varchar(60)') {
                    if ($row['password'] == crypt($password, $row['password'])) {
                        changepassword($username, $password);
                    }
                }
            }
        }
        $hasher = new PasswordHash(8, false);
        if ($hasher->CheckPassword($password, $row['password'])) {
            return 1;
        }
    }
    //end if
    return 0;
}
开发者ID:samyscoub,项目名称:librenms,代码行数:30,代码来源:mysql.inc.php


注:本文中的crypt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。