编辑
2023-10-15
后端
00
请注意,本文编写于 572 天前,最后修改于 572 天前,其中某些信息可能已经过时。

常用的加密和密码验证

go
package hash import ( "fmt" "golang.org/x/crypto/bcrypt" ) func BcryptHash(password string) string { bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) if err != nil { fmt.Println("加密失败") panic(err) } return string(bytes) } func BcryptCheck(password, hash string) bool { err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) return err == nil } func BcryptIsHashed(str string) bool { // bcrypt 加密后的长度等于 60 return len(str) == 60 }

本文作者:yowayimono

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!