• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP crypt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CreateHash

 public function CreateHash($input)
 {
     global $cphp_config;
     $hash = crypt($input, "\$5\$rounds=50000\${$this->uSalt}{$cphp_config->salt}\$");
     $parts = explode("\$", $hash);
     return $parts[4];
 }
开发者ID:GodOfConquest,项目名称:redonate,代码行数:7,代码来源:user.php


示例17: login

 public function login($user, $passw, $token, $device_id)
 {
     $resultToken = mysql_query("SELECT COUNT(*) FROM aplicacion WHERE sesion_token = '{$token}' and id_dispositivo = '{$device_id}' and vencimiento_sesion > CURRENT_TIMESTAMP ");
     $countToken = mysql_fetch_row($resultToken);
     if ($countToken[0] == 0) {
         $result = mysql_query("SELECT COUNT(*) FROM usuarios WHERE correo='{$user}' ");
         $count = mysql_fetch_row($result);
         if ($count[0] == 0) {
             return false;
         } else {
             $resultPass = mysql_query("SELECT contrasena FROM usuarios WHERE correo='{$user}' ");
             $arrPass = mysql_fetch_row($resultPass);
             if (crypt($passw, $arrPass[0]) == $arrPass[0]) {
                 // crear token
                 $tokenNuevo = base64_encode($user . mt_rand());
                 $resultToken = mysql_query("SELECT COUNT(*) FROM aplicacion WHERE correo='{$user}'");
                 $countToken = mysql_fetch_row($resultToken);
                 if ($countToken[0] == 0) {
                     $sql_usr = "INSERT INTO aplicacion (correo,sesion_token,id_dispositivo ,vencimiento_sesion) VALUES ('{$user}', '{$tokenNuevo}', '{$device_id}', Date_Add(CURRENT_TIMESTAMP, INTERVAL 30 DAY))";
                 } else {
                     $sql_usr = "UPDATE aplicacion SET sesion_token = '{$tokenNuevo}', id_dispositivo  = '{$device_id}', vencimiento_sesion = Date_Add(CURRENT_TIMESTAMP, INTERVAL 30 DAY) Where correo = '{$user}'";
                 }
                 mysql_query($sql_usr);
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         return true;
     }
 }
开发者ID:aopazo,项目名称:web,代码行数:32,代码来源:funciones_bd.php


示例18: verifyPassword

 private function verifyPassword($clearPassword, $hashPassword)
 {
     //PHP 5.5.0
     //return password_verify($clearPassword,$hashPassword);
     //PHP <5.5.0
     return crypt($clearPassword, $hashPassword) == $hashPassword;
 }
开发者ID:annacrea,项目名称:ChezPaolo,代码行数:7,代码来源:CustomerModel.class.php


示例19: passwordVerifyUF

function passwordVerifyUF($password, $hash)
{
    if (getPasswordHashTypeUF($hash) == "sha1") {
        $salt = substr($hash, 0, 25);
        // Extract the salt from the hash
        $hash_input = $salt . sha1($salt . $password);
        if ($hash_input == $hash) {
            return true;
        } else {
            return false;
        }
    } else {
        if (getPasswordHashTypeUF($hash) == "homegrown") {
            /*used for manual implementation of bcrypt*/
            $cost = '12';
            if (substr($hash, 0, 60) == crypt($password, "\$2y\$" . $cost . "\$" . substr($hash, 60))) {
                return true;
            } else {
                return false;
            }
            // Modern implementation
        } else {
            return password_verify($password, $hash);
        }
    }
}
开发者ID:webcoderu,项目名称:php-reports,代码行数:26,代码来源:funcs.php


示例20: my_hash

 public static function my_hash($var)
 {
     $salt = 'ABC';
     $salt2 = 'CBA';
     $var = crypt(md5($var . $salt), $salt2);
     return $var;
 }
开发者ID:serg234,项目名称:practic,代码行数:7,代码来源:libs.class.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP csv_explode函数代码示例发布时间:2022-05-24
下一篇:
PHP crum_appear_effects函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap