func (u *User) HashPassword() error {
	// check length
	if len(u.Password) == 0 {
		return nil
	}

	// generate hash from password
	hash, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
	if err != nil {
		return err
	}

	// save hash
	u.PasswordHash = hash

	// clear password
	u.Password = ""

	return nil
}
func (u *User) HashPassword() error {
	
	if len(u.Password) == 0 {
		return nil
	}

	
	hash, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
	if err != nil {
		return err
	}

	
	u.PasswordHash = hash

	
	u.Password = ""

	return nil
}
func ( u * User ) HashPassword ( ) error { // check length if len ( u . Password ) == 0 { return nil } // generate hash from password hash , err := bcrypt . GenerateFromPassword ( [ ] byte ( u . Password ) , bcrypt . DefaultCost ) if err != nil { return err } // save hash u . PasswordHash = hash // clear password u . Password = " " return nil }
// HashPassword will hash Password and set PasswordHash.
HashPassword will hash Password and set PasswordHash .