added: password hash
This commit is contained in:
parent
12cf796d69
commit
f5162fcd66
2 changed files with 17 additions and 0 deletions
|
|
@ -5,4 +5,6 @@ import "github.com/gin-gonic/gin"
|
|||
type Utils interface {
|
||||
IsEmail(email string) bool
|
||||
GetUserUuidFromContext(c *gin.Context) (string, error)
|
||||
HashPassword(password string) (string, error)
|
||||
ComparePasswords(hashedPassword string, plainPassword string) error
|
||||
}
|
||||
|
|
|
|||
15
pkg/utils/password.go
Normal file
15
pkg/utils/password.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package utils
|
||||
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
|
||||
func (u *Utils) HashPassword(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
||||
func (u *Utils) ComparePasswords(hashedPassword string, plainPassword string) error {
|
||||
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue