mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-04 00:47:43 +08:00
login feature
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "unicode"
|
||||
import (
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func isASCII(s string) bool {
|
||||
for _, c := range s {
|
||||
@@ -11,3 +15,14 @@ func isASCII(s string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// HashPassword generates a bcrypt hash for the given password.
|
||||
func HashPassword(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
// VerifyPassword verifies if the given password matches the stored hash.
|
||||
func VerifyPassword(password, hash string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user