Final changes to hash migration

This commit is contained in:
Tracker-Friendly 2024-02-25 19:05:22 +00:00
parent d1e6576b2c
commit f159bd31e9
2 changed files with 18 additions and 30 deletions

24
main
View File

@ -179,12 +179,8 @@ async def apilogin():
data = await request.get_json() data = await request.get_json()
username = data["username"] username = data["username"]
password = data["password"] password = data["password"]
passwordchange = data["passwordchange"]
usernames_old = ['EXAMPLE'] newpass = data["newpass"]
migrate = False
if username in usernames_old:
migrate = True
check_username_thing = check_username_taken(username) check_username_thing = check_username_taken(username)
@ -205,24 +201,12 @@ async def apilogin():
conn.commit() conn.commit()
conn.close() conn.close()
if migrate == False:
return {
"key": randomCharacters
}, 200
else:
return { return {
"key": randomCharacters, "key": randomCharacters,
"migrate": "1"
}, 200 }, 200
@app.route("/api/supersecretapi", methods=("GET", "POST")) if str(passwordchange) == "1":
def supersecretapi(): hashedpassword = generate_password_hash(newpass)
if request.method == "POST":
data = request.get_json()
username = data["username"]
password = data["password"]
hashedpassword = generate_password_hash(password)
conn = get_db_connection() conn = get_db_connection()
conn.execute("UPDATE users SET password = ? WHERE username = ?", (hashedpassword, username)) conn.execute("UPDATE users SET password = ? WHERE username = ?", (hashedpassword, username))
conn.commit() conn.commit()

View File

@ -110,7 +110,9 @@ signupButton.addEventListener("click", (event) => {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
username: username, username: username,
password: await hashpass(password) password: await hashpass(password),
passwordchange: 0,
newpass: 0
}), }),
headers: { headers: {
"Content-type": "application/json; charset=UTF-8" "Content-type": "application/json; charset=UTF-8"
@ -132,7 +134,9 @@ signupButton.addEventListener("click", (event) => {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
username: username, username: username,
password: await hashpassold(password) password: await hashpassold(password),
passwordchange: 1,
newpass: await hashpass(password)
}), }),
headers: { headers: {
"Content-type": "application/json; charset=UTF-8" "Content-type": "application/json; charset=UTF-8"