def change_password(): print(request.data) data = json.loads(request.data) password = data.get("password", None) if password: db.change_password(current_identity, password) return 'OK'
def post(self): user_id = self.get_current_user() messages = self.messages.copy() if self.get_argument('email-form', default=None): mail = self.get_argument('email', default='') letter = self.get_argument('newsletter', default=False) resubscribe = self.get_argument('resubscribe', default=False) == 'on' db.change_preferences(user_id, mail, letter, resubscribe) messages['mail'] = 'Mail preferences updated' elif self.get_argument('password-form', default=None): password = self.get_argument('current_password') new_pw = self.get_argument('password') new_pw_dup = self.get_argument('password_dup') if new_pw != new_pw_dup: messages['password_error'] = 'Passwords don\'t match' else: try: db.change_password(user_id, password, new_pw) messages['password'] = '******' except db.UserError as e: messages['password_error'] = e.message prefs = db.get_preferences(user_id) self.render('settings.html', prefs=prefs, **messages)
def change_password(): if request.method == "GET": token = request.args.get("t") if token is None: return render_template('register.html') return render_template( 'change_password.html', TOKEN=token, COOKIES_NOTIFICATION=tools.show_cookies_policy(), LOGGED_IN=tools.is_logged_in()) elif request.method == "POST": try: form = tools.ChangePasswordForm(request.form) password = bcrypt_sha256.using(salt=config.salt).hash( str(form.password.data)) db.change_password(form.token.data, password) flash("You have successfully changed your password") return render_template( "register.html", COOKIES_NOTIFICATION=tools.show_cookies_policy(), LOGGED_IN=tools.is_logged_in()) except Exception as e: flash( "Your password was not changed, please contact us at %s and we will assist you promptly." % config.email_config["admin_email"]) return render_template( 'change_password.html', COOKIES_NOTIFICATION=tools.show_cookies_policy(), LOGGED_IN=tools.is_logged_in())
def POST_change_password(self): i = web.input('current_password', 'new_password') f = forms.change_password() if not f.validates(): current = (not f.current_password.errors and i.current_password or '') new = (not f.new_password.errors and i.new_password or '') f.fill(current_password=current, new_password=new) return render('change_password', vars=locals()) db.change_password(i.new_password) auth.signin(i.new_password) web.seeother('settings')
def changepassword(): password=request.form['old_password'] username= session['username'] if db.check_password(username,password) == False: print(request.form['new_password']) error = 'Invalid password' print("1") elif request.form['new_password'] != request.form['confirm_password']: error = 'Inputted password and confirmed password, must match' print("olikA LÖSEN") else: print("2") db.change_password(session['username'],request.form['new_password']) print("3") return redirect(url_for('userinfo(username)'))
def edit_password(pass_id): """This view processes password editing. It processes '/api/password/edit/<int:pass_id>' route and accepts POST requests. It requires newPassword to be in the request.form dict. This view encrypts newPassword with CRYPTING_OBJ and inserts it to db. :Parameters: - `pass_id`: id of the password to change. :Returns: template with success or failure messages, depending on result. """ current_user = flask_login.current_user encrypted_pass = CRYPTING_OBJ.encrypt(request.form['newPassword'] .encode('utf-8')) rows_affected = db.change_password(request.form['newLogin'], encrypted_pass, pass_id, current_user.uid) if rows_affected: message = 'Password has been changed!' else: message = 'Password has not been changed. Some error has occured!' template = get_template('service_message.html') return template.render(current_user=current_user, message=message)
def post(self): userid = self.get_current_user() password = self.get_argument('current_password') new_pw = self.get_argument('password') new_pw_dup = self.get_argument('password_dup') if new_pw != new_pw_dup: error = u'?context=password&error=' + tornado.escape.url_escape('Passwords don\'t match') self.redirect('/settings' + error) else: try: db.change_password(userid, password, new_pw) self.redirect('/settings') except db.UserError as e: error = u'?context=password&error=' + tornado.escape.url_escape(e.message) self.redirect('/settings' + error)
def edit_password(): if request.method == "GET": return render_template("edit-password.html") elif request.method == "POST": try: user_id = session["user"]["id"] if not require_fields("old_password", "new_password"): raise AppError("表单项未完全填写") old_password, new_password = request.form[ "old_password"], request.form["new_password"] if not db.recheck_password(user_id, old_password): raise AppError("原密码错误") db.change_password(user_id, new_password) session.pop("user") return render_template("edit-password.html", successes=("密码已成功修改,请重新登录", )) except AppError as e: return render_template("edit-password.html", errors=(e.message, ))
def account_man(): if request.method == 'POST': if request.form.get('username', None) != None and request.form.get( 'password', None) != None and len( request.form.get('username', None)) > 0 and len( request.form.get('password', None)) > 0: error = None if request.form.get('new_username', None) != None and len( request.form.get('new_username', None)) > 0: if change_username(request.form.get('username', None), request.form.get('password', None), request.form.get('new_username', None)) == False: error = True if request.form.get('new_name', None) != None and len( request.form.get('new_name', None)) > 0: if change_name(get_first_admin(), request.form.get('password', None), request.form.get('new_name', None)) == False: error = True if request.form.get('new_password', None) != None and len( request.form.get('new_password', None)) > 0: if change_password(request.form.get('username', None), request.form.get('password', None), request.form.get('new_password', None)) == False: error = True return render_template('account_man.html', error=error, password_error=False) else: password_error = True return render_template('account_man.html', password_error=password_error) if 'username' in session: username = session['username'] name = get_first_admin() return render_template('account_man.html', username=username, name=name) else: return redirect(url_for('login'))
def save_password_click(self): if self.NewPasswordEdit.text() == self.RepeatNewPasswordEdit.text(): num_bs = 0 num_ls = 0 num_c = 0 isspace = 0 newPassword = self.NewPasswordEdit.text() for i in newPassword: if i.isupper(): num_bs += 1 if i.isdigit(): num_c += 1 if i.islower(): num_ls += 1 if i == ' ': isspace += 1 if len(newPassword) >= 6 and len( newPassword) <= 16 and num_bs != 0 and num_c != 0 and num_ls != 0 and isspace == 0: self.ErrorLabel.setText('Пароль изменён') db.change_password(newPassword) else: self.ErrorLabel.setText('Ошибка') else: self.ErrorLabel.setText('Пароли не совпадают')
flag = False break except FileNotFoundError: print("Никогда не видел такого файла") else: print("Вы не смогли пройти аутентификацию") os.chdir('..') os.chdir('..') if command == 3: third = db.delete_acc() if third is True: print("Аккаунт удален") else: print("Вы не смогли удалить аккаунт") if command == 4: fourth = db.change_password() if fourth is True: print("Пароль изменен успешно") else: print("Вы не смогли изменить пароль") if command == 5: print("Осуществляется выход") exit(0) else: print("Работайте с меню!") except SyntaxError: print("Не та команда") except ValueError: print("Не тот ввод") except PermissionError: print("Вы не можете работать с программой из-за проблем с допуском")
def post(self): user_id = self.get_current_user() password = self.get_argument('password') db.change_password(user_id, password) self.redirect('/account')
def update_pass(username, password): return db.change_password(username, encrypt(password))