def change_password(): form = ChangePassword() if form.validate_on_submit(): exist_stmt_auth = "SELECT EXISTS(SELECT * FROM author WHERE Email=%s)" cursor = db.connection.cursor() cursor.execute(exist_stmt_auth, [form.email.data]) exists = cursor.fetchall() exists = int(exists[0][0]) if not exists: return render_template("change_password.html", form=form, message="Email not found!") else: print("****************") print("EMAIL =", form.email.data, "PASSWORD ="******"****************") reset_pswd = "UPDATE author SET Password=%s WHERE Email=%s" cursor = db.connection.cursor() cursor.execute(reset_pswd, [form.password.data, form.email.data]) db.connection.commit() _ = cursor.fetchall() return render_template("change_password.html", form=form, message="Password changed successfully!") return render_template("change_password.html", form=form)
def change_password(id): if user_in_session(): error = None user = User.query.filter_by(id=int(id)).first() form = ChangePassword() if form.validate_on_submit() and request.method == 'POST': password_user = sha256((form.password_user.data).encode()) if validate_password(user.username, password_user.hexdigest()): new_password = sha256((form.new_password.data).encode()) confirm_new_password = sha256((form.confirm_new_password.data).encode()) if new_password.hexdigest() == confirm_new_password.hexdigest(): user.password = new_password.hexdigest() db.session.add(user) db.session.commit() flash('Your password has been changed successfuly!') return redirect(url_for('profile')) else: error = 'New passwords no match!' else: error = 'Incorrect actual password' return render_template('auth/session-started/change_password.html', form=form, error=error) else: abort(404)
def user(user_id): user = User.query.filter_by(id = user_id).first() kicks = Kicks.query.all() form = ChangePassword() account = EditAccountInfo(obj=user) tix_per_kick = [] tix_count = [] all_tix = Tickets.query.filter_by(user_id = user_id).all() for t in all_tix: print t.kicks_id, t.num_tickets kick = Kicks.query.filter_by(id = t.kicks_id).first() print kick.shoe_name obj = {'kick': kick, 'num_tickets': t.num_tickets, 'date': t.date} tix_count.append(obj) #updates password if form.validate_on_submit(): if check_password_hash(user.password, form.old.data): if form.new.data == form.confirm_new.data: user.password = generate_password_hash(form.new.data) db.session.add(user) db.session.commit() flash('Password was updated') else: flash('Make sure the new password matches') else: flash('Wrong password') #edit account info if account.validate_on_submit(): print 'account was updated' user.firstname = account.firstname.data user.lastname = account.lastname.data user.email = account.email.data user.address_street = account.address_street.data user.address_city = account.address_city.data user.address_state = account.address_state.data user.address_zipcode = account.address_zipcode.data user.address_country = 'USA' #Commits changes db.session.add(user) db.session.commit() flash('Info updated!') else: print account.errors print g.user.id print user_id if int(g.user.id) == int(user_id): return render_template('account.html', user = user, form = form, tix = tix_count, edit_form = account) else: return render_template('unauthorized.html')
def change_password(): form = ChangePassword() if form.validate_on_submit(): data_obj = User.query.filter_by(id=current_user.id).first() data_obj.password = form.password.data db.session.merge(data_obj) logout_user() return redirect(url_for("auth.login_page")) return render_template("user_control/change_password.html", form=form)
def change_password(token): """ produces form for changing password""" user = User.query.filter(User.reset_token == token).first() if user: form = ChangePassword() if form.validate_on_submit(): pwd = form.password.data user.update_password(pwd) user.reset_token = None db.session.commit() flash("You have successfully changed your password", 'success') return redirect('/login') return render_template('change_password.html', form=form)
def changePassword(): form = ChangePassword() if form.validate_on_submit(): user = User.query.filter_by(username=current_user.username).first() print(check_password_hash(user.password, form.old.data)) if check_password_hash(user.password, form.old.data): user.password = generate_password_hash(form.new.data, method='sha256') db.session.add(user) db.session.commit() flash('Password successfully changed.') return redirect(url_for('logout')) flash('Invalid password.') return render_template('change_password.html', form=form)
def changepassword(): form = ChangePassword() user = users.find_one({'username': current_user.get_id()}) if form.validate_on_submit(): users.update_one(user, { '$set': { 'password': generate_password_hash(form.password.data) } }) flash('Password Changed', 'info') return redirect(url_for('index')) return render_template('changepassword.html', title="Change Password", form=form)
def change_password(): username = current_user.username user = User.query.filter_by(username=username).first() form = ChangePassword() if form.validate_on_submit(): old_password = form.old_password.data new_password = form.new_password.data confirm_password = form.confirm_password.data if (user and (check_password_hash(user.password, old_password) and (new_password == confirm_password))): update_password(user_id=user.id, password=generate_password_hash(new_password)) return redirect(f"/user/{username}") return render_template("change_password.html", form=form)
def reset_password(email): try: user = mongo.db.users form = ChangePassword() if form.validate_on_submit(): new_password = request.form['change_password'] hashed_password = bcrypt.generate_password_hash( new_password).decode('utf-8') findquery = {"email": email} newquery = {"$set": {'password': hashed_password}} status = user.update_one(findquery, newquery) return "<h1>Successfully Changed</h1>" else: return render_template('reset_password.html', form=form, email=email) except Exception: return dumps({'status': 'error', 'message': str(Exception)})
def settings(): latest_messages = current_user.contacts_latest_messages() password_form = ChangePassword() wrong_password = False if password_form.validate_on_submit(): if current_user.verify_password(password_form.old_password.data): current_user.change_password(password_form.new_password.data) db.session.commit() flash(u"Nouveau mot de passe enregistré") return redirect(url_for('auth.logout')) else: wrong_password = True return render_template('prof/settings.html', user=current_user.serialize(), password_form=password_form, wrong_password=wrong_password, latest_messages=latest_messages)
def change_pwd(): form = ChangePassword() if form.validate_on_submit(): if form.curpwd.data==base64.b64decode(app.config['PASSWORD']): if form.password1.data==form.password2.data: s = 'USERNAME = "******"\nPASSWORD = "******"'.format(base64.b64encode(form.username.data), base64.b64encode(form.password1.data)) with open('auth.py', 'w') as f: f.write(s) if form.username.data!=base64.b64decode(app.config['USERNAME']): flash('New username have been saved.') app.config['USERNAME']=base64.b64encode(form.username.data) if form.curpwd.data!=form.password1.data: flash('Password was changed succesfully.') app.config['PASSWORD']=base64.b64encode(form.password1.data) logout_user() else: flash('Introduced a different passwords', 'error') else: flash('Entered an incorrect current password.', 'error') return redirect(url_for('change_pwd')) return render_template("password.html", title = 'Change password', form = form, username=base64.b64decode(app.config['USERNAME']))