2013-08-03 2 views
4

노드 응용 프로그램에서 사용자의 기존 암호를 확인할 때 [Error: data and hash arguments required] 오류가 발생합니다. 상황은 사용자 프로필 페이지에서 변경하기 전에 기존 비밀번호를 확인하도록 사용자에게 요청합니다. 내 스택은 bcrypt와 함께 passport-local을 사용하는 node + mondodb (몽구스 경유)이다.node.js에서 passport-local 및 bcrypt로 암호 확인 및 업데이트

관련 코드는 다음과 같습니다

// code trying to match that returns the aforementioned error 
req.user.comparePassword(req.body.password, function (err, isMatch) { 
    if (err) { 
     return console.error(err); 
    } 
    if (isMatch) { 
     console.log('passwords match'); 
     // now save new password 

     // Password verification 
     userSchema.methods.comparePassword = function (candidatePassword, cb) { 
      bcrypt.compare(candidatePassword, this.password, function (err, isMatch) { 
       if (err) return cb(err); 
       cb(null, isMatch); 
      }); 
     }; 
    } 
} 

req.user는 현재 사용자 객체를 참조하고,`req.body.password '는 사용자의 POST에서 얻은 암호입니다. Passport-local 예제에서 UserSchema, 여권 전략 및 Bcrypt 구성을 사용하고 있습니다. here.

업데이트하기 전에 일치하는지 확인하는 방법에 대한 지침을 제공 할 수 있습니까?

답변

5

그래서 bcrypt.compare은 인수 중 하나 인 data 또는 hash이 누락되었다고 불평하고 있습니다. 따라서 this.passwordnull 또는 undefined을 반환합니다. 해당 사용자의 데이터베이스 레코드를 확인하고 유효한 해시가 저장되어 있는지 확인하십시오.

관련 문제