Add command to hash password directly

Useful for resetting passwords manually.
This commit is contained in:
Eli Ribble 2026-01-26 18:42:30 +00:00
parent 940f3901be
commit c276cbac0b
No known key found for this signature in database
2 changed files with 38 additions and 3 deletions

View file

@ -131,7 +131,7 @@ func SignoutUser(r *http.Request, user *models.User) {
}
func SignupUser(ctx context.Context, username string, name string, password string) (*models.User, error) {
passwordHash, err := hashPassword(password)
passwordHash, err := HashPassword(password)
if err != nil {
return nil, fmt.Errorf("Cannot signup user, failed to create hashed password: %w", err)
}
@ -182,7 +182,7 @@ func findUser(ctx context.Context, user_id int) (*models.User, error) {
return user, err
}
func hashPassword(password string) (string, error) {
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
@ -205,7 +205,7 @@ func validatePassword(password, hash string) bool {
}
func validateUser(ctx context.Context, username string, password string) (*models.User, error) {
passwordHash, err := hashPassword(password)
passwordHash, err := HashPassword(password)
if err != nil {
return nil, fmt.Errorf("Failed to hash password: %w", err)
}