def changePassword(): if 'logged_in' not in session: return redirect('/login') oldpass = request.form.get('old-password') newpass1 = request.form.get('new-password') newpass2 = request.form.get('new-password-repeat') if not oldpass or not newpass1 or not newpass2: flash('Please provide all the data', 'error') return redirect(url_for('showChangePassword')) user = User.get(User.id == session['user_id']) if user.password != hashfunc(oldpass): flash('The password you entered does not match your old password.', 'error') return redirect(url_for('showChangePassword')) if newpass1 != newpass2: flash('The new passwords do not match.', 'error') return redirect(url_for('showChangePassword')) user.password = hashfunc(newpass1) user.save() flash('Password successfully changed.', 'success') return redirect('/')
def changePassword(): if 'logged_in' not in session: return redirect( '/login' ) oldpass = request.form.get( 'old-password' ) newpass1 = request.form.get( 'new-password' ) newpass2 = request.form.get( 'new-password-repeat' ) if not oldpass or not newpass1 or not newpass2: flash( 'Please provide all the data', 'error' ) return redirect( url_for( 'showChangePassword' ) ) user = User.get( User.id == session[ 'user_id' ] ) if user.password != hashfunc( oldpass ): flash( 'The password you entered does not match your old password.', 'error' ) return redirect( url_for( 'showChangePassword' ) ) if newpass1 != newpass2: flash( 'The new passwords do not match.', 'error' ) return redirect( url_for( 'showChangePassword' ) ) user.password = hashfunc( newpass1 ) user.save() flash( 'Password successfully changed.', 'success' ) return redirect( '/' )
def should_write(output, path): if os.path.isfile(path): file_h = open(path, 'rb') contents = file_h.read() file_h.close() current_hash = utils.hashfunc(contents) encode_txt = output['text'].encode('utf-8') new_hash = utils.hashfunc(encode_txt) if current_hash == new_hash: return False return True
def validate_user( cls, username, password ): try: user = User.get( User.username == username ) if user.password != hashfunc( password ): raise ValueError( 'Wrong password' ) return user except DoesNotExist: raise ValueError( 'No user with a given username' )
def create_user( cls, username, password ): if not username or len( username ) < 4: raise ValueError( 'Incorrect username' ) if not password or len( password ) < 8: raise ValueError( 'Incorrect password' ) try: user = cls.create( username = username, password = hashfunc( password ) ) return user except IntegrityError: raise ValueError( 'Username already in use' )
def deleteUser(): if 'logged_in' not in session: return redirect( '/login' ) password = request.form.get( 'password' ) if not password: flash( 'Please enter your password to proceed.', 'error' ) return redirect( url_for( 'showDeleteUser' ) ) user = User.get( User.id == session[ 'user_id' ] ) if user.password != hashfunc( password ): flash( 'Incorrect password.', 'error' ) return redirect( url_for( 'showDeleteUser' ) ) user.delete_instance( recursive = True ) return redirect( '/signout' )
def deleteUser(): if 'logged_in' not in session: return redirect('/login') password = request.form.get('password') if not password: flash('Please enter your password to proceed.', 'error') return redirect(url_for('showDeleteUser')) user = User.get(User.id == session['user_id']) if user.password != hashfunc(password): flash('Incorrect password.', 'error') return redirect(url_for('showDeleteUser')) user.delete_instance(recursive=True) return redirect('/signout')
def processSignup(): name = request.form.get( 'name' ) email = request.form.get( 'email' ) pass1 = request.form.get( 'password' ) pass2 = request.form.get( 'password-repeat' ) if pass1 != pass2: flash( 'Passwords do not match.', 'error' ) return redirect( url_for( 'showSignup' ) ) if not name or not email or not pass1 or not pass2: flash( 'Please provide all the data.', 'error' ) return redirect( url_for( 'showSignup' ) ) try: user = User( name = name, email = email, password = hashfunc( pass1 ) ) user.save() except IntegrityError: flash( 'Given email already in use.', 'error' ) return redirect( url_for( 'showSignup' ) ) flash( 'Successfully signed up.', 'success' ) return redirect( url_for( 'index' ) )
def processSignup(): name = request.form.get('name') email = request.form.get('email') pass1 = request.form.get('password') pass2 = request.form.get('password-repeat') if pass1 != pass2: flash('Passwords do not match.', 'error') return redirect(url_for('showSignup')) if not name or not email or not pass1 or not pass2: flash('Please provide all the data.', 'error') return redirect(url_for('showSignup')) try: user = User(name=name, email=email, password=hashfunc(pass1)) user.save() except IntegrityError: flash('Given email already in use.', 'error') return redirect(url_for('showSignup')) flash('Successfully signed up.', 'success') return redirect(url_for('index'))
def processLogin(): email = request.form.get( 'email' ) passwd = request.form.get( 'password' ) if not email or not passwd: flash( 'Please enter all the data.', 'error' ) return redirect( url_for( 'showLogin' ) ) try: user = User.get( User.email == email ) except User.DoesNotExist: flash( 'Wrong email address', 'error' ) return redirect( url_for( 'showLogin' ) ) if user.password != hashfunc( passwd ): flash( 'Wrong password', 'error' ) return redirect( url_for( 'showLogin' ) ) session[ 'logged_in' ] = True session[ 'name' ] = user.name session[ 'email' ] = user.email session[ 'user_id' ] = user.id return redirect( url_for( 'index' ) )
def processLogin(): email = request.form.get('email') passwd = request.form.get('password') if not email or not passwd: flash('Please enter all the data.', 'error') return redirect(url_for('showLogin')) try: user = User.get(User.email == email) except User.DoesNotExist: flash('Wrong email address', 'error') return redirect(url_for('showLogin')) if user.password != hashfunc(passwd): flash('Wrong password', 'error') return redirect(url_for('showLogin')) session['logged_in'] = True session['name'] = user.name session['email'] = user.email session['user_id'] = user.id return redirect(url_for('index'))