Exemplo n.º 1
0
def login():
    msg = ''
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
        username = request.form['username']
        password = request.form['password']
        salted_pass = salt_password(password)
        hashed_pass = bcrypt.generate_password_hash(salted_pass)
        usernamedata = database.execute(
            "SELECT username FROM user WHERE username=:username", {
                "username": username
            }).fetchone()
        if usernamedata is None:
            msg = 'NOT WORKING'
            return render_template(
                'auth/login.html',
                msg='You have entered an Incorrect Username or Password')
        else:
            msg = 'WORKING'
            session['loggedin'] = True
            session['username'] = usernamedata['username']
            return render_template('index.html',
                                   usernames=names,
                                   loggedinaccount=session['username'])

    return render_template('auth/login.html', msg='')
Exemplo n.º 2
0
def login():
    if request.method == 'POST':
        _username = request.form['username']
        _password = request.form['password']
        
        user = User.query.filter_by(username=_username).first()
        
        if bcrypt.check_password_hash(user.password, salt_password(_password)):
            return redirect('/')
        else:
            print("there was an error creating your account") 
            return render_template('index.html')
    else:
        return render_template('auth/login.html')
Exemplo n.º 3
0
def login():
    if request.method == 'POST':
        _email = request.form['email']
        _password = request.form['password']

        salted_pass = salt_password(_password)
        #hashed_pass = bcrypt.generate_password_hash(salted_pass)

        user = User.query.filter(User.email == _email).first()
        if user is None:
            return "That email address was not found."
        else:
            if not bcrypt.check_password_hash(user.password, salted_pass):
                return "The password is incorrect"
            else:
                return "The password is correct"

        return redirect('/')
    else:
        return render_template('auth/login.html')
Exemplo n.º 4
0
def signup():
    if request.method == 'POST':
        _username = request.form['username']
        _email = request.form['email']
        _password = request.form['password']
        
        salted_pass = salt_password(_password)
        hashed_pass = bcrypt.generate_password_hash(salted_pass)
        
        new_user = User(username=_username, email=_email, password=hashed_pass)
        
        try:
            db.session.add(new_user)
            db.session.commit()
        except:
            print("there was an error creating your account") 
            return redirect('/')
        return redirect('/')
    else:
        return render_template('auth/reg.html')