MCPcopy Index your code
hub / github.com/dnote/dnote / UpdateUserPassword

Function UpdateUserPassword

pkg/server/app/users.go:146–164  ·  view source on GitHub ↗

UpdateUserPassword updates a user's password with validation

(db *gorm.DB, user *database.User, newPassword string)

Source from the content-addressed store, hash-verified

144
145// UpdateUserPassword updates a user's password with validation
146func UpdateUserPassword(db *gorm.DB, user *database.User, newPassword string) error {
147 // Validate password
148 if err := validatePassword(newPassword); err != nil {
149 return err
150 }
151
152 // Hash the password
153 hashedPassword, err := bcrypt.GenerateFromPassword([]byte(newPassword), bcrypt.DefaultCost)
154 if err != nil {
155 return pkgErrors.Wrap(err, "hashing password")
156 }
157
158 // Update the password
159 if err := db.Model(&user).Update("password", string(hashedPassword)).Error; err != nil {
160 return pkgErrors.Wrap(err, "updating password")
161 }
162
163 return nil
164}
165
166// RemoveUser removes a user from the system
167// Returns an error if the user has any notes or books

Callers 4

PasswordResetMethod · 0.92
PasswordUpdateMethod · 0.92
userResetPasswordCmdFunction · 0.92
TestUpdateUserPasswordFunction · 0.85

Calls 2

validatePasswordFunction · 0.85
UpdateMethod · 0.45

Tested by 1

TestUpdateUserPasswordFunction · 0.68