我正在用 golang 編寫一個基本的密碼認(rèn)證系統(tǒng)。我使用 bcrypt 對密碼進(jìn)行散列并將散列保存在數(shù)據(jù)庫中。這是從數(shù)據(jù)庫中檢索經(jīng)過身份驗證的帳戶的函數(shù)。func FindAccount(db *gorp.DbMap, email, password string) (*Account, error) { account, err := FindByEmail(db, email) if err != nil { return nil, err } if account == nil { return nil, nil } if err := bcrypt.CompareHashAndPassword([]byte(account.HashedPassword), []byte(password)); err != nil { return nil, err } return account, nil}和來電者:account, err := FindAccount(db, email, password)if err != nil { if err == bcrypt.ErrMismatchedHashAndPassword { log.Printf("Why doesn't this condition match?") return nil, EmailPasswordInvalidError{} } log.Printf("bcrypt.Err: %p, %#v", bcrypt.ErrMismatchedHashAndPassword, bcrypt.ErrMismatchedHashAndPassword) log.Printf("err : %p, %#v", err, err) return nil, err}當(dāng)我使用此代碼并提供無效的電子郵件和密碼時,會發(fā)生以下情況:sessions.go:51: bcrypt.Err: 0xc2080290b0, &errors.errorString{s:"crypto/bcrypt: hashedPassword is not the hash of the given password"}sessions.go:52: err : 0xc2080291e0, &errors.errorString{s:"crypto/bcrypt: hashedPassword is not the hash of the given password"}為什么指針地址不同?我們不能只比較錯誤嗎?
- 1 回答
- 0 關(guān)注
- 251 瀏覽
添加回答
舉報
0/150
提交
取消