Created
June 14, 2018 20:49
-
-
Save Cibernomadas/830e8dcea6bcb2ba80ac54c80801714d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (u *User) SetPassword(p string) error { | |
bytes, err := bcrypt.GenerateFromPassword([]byte(p), bcrypt.DefaultCost) | |
if err != nil { | |
return err | |
} | |
u.Password = string(bytes) | |
return nil | |
} | |
func (u *User) CheckPassword(p string) bool { | |
err := bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(p)) | |
return err == nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment