changing password in settings dialog

This commit is contained in:
azivner 2017-09-12 22:23:57 -04:00
parent b0957a0c8f
commit 3e97cdf085
3 changed files with 48 additions and 6 deletions

View file

@ -2,18 +2,20 @@ import scrypt # pip install scrypt
import sql import sql
def getVerificationHash(password): def getVerificationHash(password):
# getOption returns unicode bytes which scrypt doesn't like salt = sql.getOption('verification_salt')
salt = sql.getOption('verification_salt').encode('ascii', 'ignore')
return getScryptHash(password, salt) return getScryptHash(password, salt)
def getEncryptionHash(password): def getEncryptionHash(password):
# getOption returns unicode bytes which scrypt doesn't like salt = sql.getOption('encryption_salt')
salt = sql.getOption('encryption_salt').encode('ascii', 'ignore')
return getScryptHash(password, salt) return getScryptHash(password, salt)
def getScryptHash(password, salt): def getScryptHash(password, salt):
# scrypt doesn't like unicode strings
password = password.encode('ascii', 'ignore')
salt = salt.encode('ascii', 'ignore')
hashed = scrypt.hash(password=password, hashed = scrypt.hash(password=password,
salt=salt, salt=salt,
N=16384, N=16384,

View file

@ -3,6 +3,7 @@ from flask_login import login_required
import hashlib import hashlib
import binascii import binascii
import sql import sql
import change_password
password_api = Blueprint('password_api', __name__) password_api = Blueprint('password_api', __name__)
@ -19,4 +20,13 @@ def verifyPassword():
return jsonify({ return jsonify({
'valid': isValid 'valid': isValid
}) })
@password_api.route('/password/change', methods = ['POST'])
@login_required
def changePassword():
req = request.get_json(force=True)
result = change_password.change_password(req['current_password'], req['new_password'])
return jsonify(result)

View file

@ -8,7 +8,37 @@ function displaySettings() {
} }
$("#changePasswordForm").submit(() => { $("#changePasswordForm").submit(() => {
console.log("Submit"); const oldPassword = $("#oldPassword").val();
const newPassword1 = $("#newPassword1").val();
const newPassword2 = $("#newPassword2").val();
$("#oldPassword").val('');
$("#newPassword1").val('');
$("#newPassword2").val('');
if (newPassword1 != newPassword2) {
alert("New passwords are not the same.");
return false;
}
$.ajax({
url: baseUrl + 'password/change',
type: 'POST',
data: JSON.stringify({
'current_password': oldPassword,
'new_password': newPassword1
}),
contentType: "application/json",
success: function (result) {
if (result.success) {
alert("Password has been changed.");
}
else {
alert(result.message);
}
},
error: () => alert("Error occurred during changing password.")
});
return false; return false;
}); });