新建后台账号,不设置密码。登陆后台,输入用户名和任意字符作为密码,系统崩溃。

bug问题 · jackdu · 于 4年前 发布 · 1552 次阅读

Invalid Argument – yii\base\InvalidArgumentException Hash is invalid.

  1. in /var/www/abc/vendor/yiisoft/yii2/base/Security.phpat line 651 642643644645646647648649650651652653654655656657658659660 {

     if (!is_string($password) || $password === '') {
         throw new InvalidArgumentException('Password must be a string and cannot be empty.');
     }
    
     if (!preg_match('/^\$2[axy]\$(\d\d)\$[\.\/0-9A-Za-z]{22}/', $hash, $matches)
         || $matches[1] < 4
         || $matches[1] > 30
     ) {
         throw new InvalidArgumentException('Hash is invalid.');
     }
    
     if (function_exists('password_verify')) {
         return password_verify($password, $hash);
     }
    
     $test = crypt($password, $hash);
     $n = strlen($test);
     if ($n !== 60) {
    
  2. in /var/www/abc/vendor/fancyecommerce/fec_admin/models/AdminUser.php at line 219– yii\base\Security::validatePassword('test', null) 213214215216217218219220221222223224225 *

    • @param string $password password to validate
    • @return boolean if password provided is valid for current user */ public function validatePassword($password) { return Yii::$app->security->validatePassword($password, $this->password_hash); }

    /**

    • Generates password hash from password and sets it to the model *
    • @param string $password
  3. in /var/www/abc/vendor/fancyecommerce/fec_admin/models/AdminUser/AdminUserLogin.php at line 38– fecadmin\models\AdminUser::validatePassword('test') 32333435363738394041424344 public function validatePassword($attribute,$params){

     if (!$this->hasErrors()) {
         $AdminUser = $this->getAdminUser();
         if (!$AdminUser) {
             $this->addError('用户名', '用户名不存在');
         }else if(!$AdminUser->validatePassword($this->password)){
             $this->addError('用户名或密码','不正确');
         }
     }
    

    }

共收到 4 条回复
jackdu#14年前 0 个赞

文件路径: /var/www/abc/vendor/fancyecommerce/fec_admin/models/AdminUser.php 我试着改了一下,故障解决了。 水平有限,大家别笑话我。 /**

 * Validates password
 *
 * @param string $password password to validate
 * @return boolean if password provided is valid for current user
 */
public function validatePassword($password)
{
    if($this->password_hash === null){
		return false;
	}else{
		return Yii::$app->security->validatePassword($password, $this->password_hash);
		
	}
}
Fecmall#24年前 0 个赞

后台新建账户,不设置密码能保存成功?

jackdu#34年前 0 个赞

是的,可以保存。 因为密码只有修改才保存,默认应该不是必选项。

Fecmall#44年前 1 个赞

@jackdu #3楼 这个问题已经修复,当时忘记回复这个帖子了

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics