def register(): # Register user to the database if (request.method == "POST"): username = request.form['username'] password = request.form['password'] reenter = request.form['re-password'] # validate inputs for registration # Check if the username already exists if check_username(username): flash("User name already exists", category='error') return redirect(url_for('register')) elif password != reenter: flash("Passwords do not match", category='error') return redirect(url_for('register')) elif len(password) < 8: flash("password must be longer than 8 characters", category='error') return redirect(url_for('register')) else: add_user(username, password) flash("Account created Successfully. You can now login", category='success') return redirect(url_for('login')) else: return render_template("register.html")
def registration(message=''): if request.method == 'POST': username = request.form['regUserName'] usr_password = request.form['regPass'] is_user = queries.check_username(username) if is_user: message = 'Username taken, please choose another.' return render_template('registration.html', message=message) else: hashed_password = password.hash_password(usr_password) queries.create_user(username, hashed_password) return redirect(url_for('index')) else: return render_template('registration.html', message=message)
def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = check_username(username) if user: if check_password_hash(user[1], password): session["user"] = username return redirect(url_for('user_home')) else: flash("Invalid password", category='error') return redirect(url_for("login")) else: flash("username doesn't exist", category='error') return redirect(url_for("login")) return render_template("login.html")
def register(): message = "false" if request.method == 'POST': username = request.form.get('username') existing_user_names = queries.check_username() for user in existing_user_names: if user['username'] == username: return render_template('register.html', message="false") else: message = "true" hashed_bytes = bcrypt.hashpw(request.form.get('password').encode('utf-8'), bcrypt.gensalt()) register_data = { 'username': username, 'password': hashed_bytes.decode('utf-8') } queries.create_user(register_data) return render_template('register.html', message=message) return render_template('register.html', message="none")
def login(): if request.method == 'POST': user_name = request.form['logUserName'] user_password = request.form['logPass'] # checking username in database isUserName = queries.check_username(user_name) if isUserName == []: return render_template('login.html', wrongpass=False) # checking password hashed_pass = queries.get_hashed_pass(user_name) check_password = password.verify_password(user_password, hashed_pass[0]['password']) if check_password: user_id = queries.get_userid_by_name(user_name) session['user_name'] = user_name session['userId'] = user_id return redirect(url_for('index')) else: return render_template('login.html', wrongpass=False) elif request.method == 'GET': return render_template('login.html')