flipped-aurora/gin-vue-admin · error
原密码错误
Error message
原密码错误
What it means
ChangePassword verifies the user's current password with utils.BcryptCheck against the stored bcrypt hash before applying the new one. When the supplied old password does not match the stored hash, it returns errors.New("原密码错误"). This is an intentional business-rule rejection, not a database or infrastructure failure.
Source
Thrown at server/service/system/sys_user.go:82
MenuServiceApp.UserAuthorityDefaultRouter(ctx, &user)
}
return &user, err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ChangePassword
//@description: 修改用户密码
//@param: u *model.SysUser, newPassword string
//@return: err error
func (userService *UserService) ChangePassword(ctx context.Context, u *system.SysUser, newPassword string) (err error) {
var user system.SysUser
err = global.GVA_DB.WithContext(ctx).Select("id, password").Where("id = ?", u.ID).First(&user).Error
if err != nil {
return err
}
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
return errors.New("原密码错误")
}
pwd := utils.BcryptHash(newPassword)
now := time.Now()
err = global.GVA_DB.WithContext(ctx).Model(&user).Updates(map[string]interface{}{
"password": pwd,
"password_updated_at": now,
"must_change_password": false,
}).Error
return err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetUserInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func (userService *UserService) GetUserInfoList(ctx context.Context, info systemReq.GetUserList) (list interface{}, total int64, err error) {View on GitHub (pinned to 3136500ef3)
Solutions
- Have the user re-enter the current password carefully (check for input-field mix-ups in the form).
- Verify the front end maps oldPassword to u.Password and newPassword to newPassword correctly in the API payload.
- If the password was recently reset by an admin or via 'forgot password', use the new password as the current one.
- In extreme cases (forgotten password), use ResetPassword via admin flow instead of ChangePassword.
Example fix
// before
await changePassword({ id, password: newPassword, newPassword }) // wrong field
// after
await changePassword({ id, password: oldPassword, newPassword: newPassword }) Defensive patterns
Strategy: try-catch
Validate before calling
// client-side: require non-empty current password before submit
if (!oldPassword || !newPassword) { throw new Error('请填写原密码和新密码') } Try / catch
try {
await changePassword({ id, password: oldPassword, newPassword })
} catch (e) {
if (e.message === '原密码错误') ElMessage.warning('原密码不正确,请重新输入')
else throw e
} Prevention
- Double-check the payload field mapping (old password vs new password).
- Inform users to re-login after an admin password reset.
- Log failed attempts server-side to detect credential stuffing.
When it happens
Trigger: Calling ChangePassword (sys_user.go:82) with u.Password (the current password) that does not hash-match user.Password fetched by user ID. Happens when the caller submits a wrong/stale old password, or when the stored hash was reset externally.
Common situations: Users mistyping their current password in a change-password form; sessions left open after an admin reset the password; front end sending the new password in the old-password field; passwords changed on another device.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/85f82318979594a2.
Report an issue: GitHub.