Skip to content

Instantly share code, notes, and snippets.

@Cibernomadas
Created June 14, 2018 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cibernomadas/830e8dcea6bcb2ba80ac54c80801714d to your computer and use it in GitHub Desktop.
Save Cibernomadas/830e8dcea6bcb2ba80ac54c80801714d to your computer and use it in GitHub Desktop.
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