Example #1
0
func convertSetPwd(converter *expressionConverter, v *ast.SetPwdStmt) (*stmts.SetPwdStmt, error) {
	return &stmts.SetPwdStmt{
		User:     v.User,
		Password: v.Password,
		Text:     v.Text(),
	}, nil
}
Example #2
0
func (e *SimpleExec) executeSetPwd(s *ast.SetPwdStmt) error {
	if len(s.User) == 0 {
		vars := e.ctx.GetSessionVars()
		s.User = vars.User
		if len(s.User) == 0 {
			return errors.New("Session error is empty")
		}
	}
	userName, host := parseUser(s.User)
	exists, err := userExists(e.ctx, userName, host)
	if err != nil {
		return errors.Trace(err)
	}
	if !exists {
		return errors.Trace(ErrPasswordNoMatch)
	}

	// update mysql.user
	sql := fmt.Sprintf(`UPDATE %s.%s SET password="******" WHERE User="******" AND Host="%s";`, mysql.SystemDB, mysql.UserTable, util.EncodePassword(s.Password), userName, host)
	_, err = e.ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(e.ctx, sql)
	return errors.Trace(err)
}