Esempio n. 1
0
def authenticate_user(username, password):
    result = User.view(get_db(), '_view/user/by_username', key=username)
    if len(result) == 0:
        raise InvalidUser('bad username')
    user = result.__iter__().next()
    if not hash_password(password, user.salt) == user.password:
        raise InvalidUser('bad password')
    return user
Esempio n. 2
0
 def register_post(self):
     try:
         form_result = RegisterForm().to_python(request.POST)
         user = User()
         user.username = form_result['username']
         pwd, salt = gen_hash_password(form_result['password'])
         user.password = pwd
         user.salt = salt
         user.store(get_db())
         c.title = 'Login'
         c.info_msgs.append('You are registered now.')
         return render('auth/login.mak')
     except formencode.Invalid, err:
         c.title = 'Register'
         html = render('auth/register.mak')
         return formencode.htmlfill.render(html, errors=err.error_dict)
Esempio n. 3
0
def user_exists(username):
    result = User.view(get_db(), '_view/user/by_username', key=username)
    if len(result) == 0:
        return False
    return True