Skip to content

Commit

Permalink
Added change password
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshShah1997 committed Aug 16, 2016
1 parent f6fcd3d commit efeb978
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Binary file modified database.db
Binary file not shown.
29 changes: 29 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,35 @@ def editProfile():
conn.close()
return render_template("editProfile.html", profileData=profileData, loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems)

@app.route("/account/profile/changePassword", methods=["GET", "POST"])
def changePassword():
if 'email' not in session:
return redirect(url_for('loginForm'))
if request.method == "POST":
oldPassword = request.form['oldpassword']
oldPassword = hashlib.md5(oldPassword.encode()).hexdigest()
newPassword = request.form['newpassword']
newPassword = hashlib.md5(newPassword.encode()).hexdigest()
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
cur.execute("SELECT userId, password FROM users WHERE email = '" + session['email'] + "'")
userId, password = cur.fetchone()
if (password == oldPassword):
try:
cur.execute("UPDATE users SET password = ? WHERE userId = ?", (newPassword, userId))
conn.commit()
msg="Success"
except:
conn.rollback()
msg = "Failure"
return msg
else:
msg = "Wrong password"
conn.close()
return msg
else:
return render_template("changePassword.html")

@app.route("/updateProfile", methods=["GET", "POST"])
def updateProfile():
if request.method == 'POST':
Expand Down
16 changes: 16 additions & 0 deletions templates/changePassword.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title>Change Password</title>
<script src={{ url_for('static', filename='js/changePassword.js') }}></script>
</head>
<body>
<form action={{ url_for('changePassword') }} method="POST">
<p>Old Password: <input type="password" name="oldpassword"></p>
<p>New Password: <input type="password" name="newpassword"></p>
<p>Confirm Password: <input type="password" name="cpassword"></p>
<input type="submit" value="Save">
</form>
</body>
</html>


4 changes: 2 additions & 2 deletions templates/profileHome.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
</div>

<div class="display">
<a href="/account/profile/view">View Profile</a>
<a href="/account/profile/edit">Edit Profile</a>
<a href="/account/profile/view">View Profile</a><br>
<a href="/account/profile/edit">Edit Profile</a><br>
<a href="/account/profile/changePassword">Change password</a>
</div>
</body>
Expand Down

0 comments on commit efeb978

Please sign in to comment.