mirror of
https://github.com/gl-inet/glkvm-cloud.git
synced 2026-09-21 01:53:23 +00:00
a23912fd89
Refine user deletion logic to avoid inconsistent states. Signed-off-by: GL.iNet-Yongping.Xie <yongping.xie@gl-inet.com>
23 lines
543 B
Go
Executable File
23 lines
543 B
Go
Executable File
package password
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const bcryptCost = 12
|
|
|
|
// HashPassword hashes a plaintext password using bcrypt.
|
|
func HashPassword(pw string) (string, error) {
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcryptCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(hash), nil
|
|
}
|
|
|
|
// VerifyPassword checks a plaintext password against a stored bcrypt hash.
|
|
func VerifyPassword(pw, hash string) bool {
|
|
if hash == "" {
|
|
return false
|
|
}
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(pw)) == nil
|
|
}
|