feat (user): add create
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var Cost = 10 // can be set by consumer
|
||||
|
||||
func Hash(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), Cost)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
func Check(password, hash string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user