Added skeleton code for register endpoint (#2)
Reviewed-on: phoenix/textsender-auth#2 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package utility
|
||||
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type HashMash struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
func (h HashMash) HashPassword() (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(h.Password), bcrypt.DefaultCost)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
func (h HashMash) CheckPasswordHash(password string, hash string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (h *HashMash) SetPassword(password string) {
|
||||
h.Password = password
|
||||
}
|
||||
Reference in New Issue
Block a user