Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.