在Yii2中提供了密码加密以及验证的一系列方法,方便我们的使用,它使用的是bcrypt算法。查看源码我们可以发现它使用的是PHP函数password_hash()和crypt()生成。
/** * $password 要加密的密码 * $hash 加密后的hash字符串 */ $hash = Yii::$app->getSecurity()->generatePasswordHash($password);
/** * $password 要验证的明文密码 * $hash 加密后的hash字符串 */ Yii::$app->getSecurity()->validatePassword($password, $hash);
原文:https://www.cnblogs.com/woods1815/p/10851270.html