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

38
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,28 +201,16 @@ async def apilogin():
conn.commit() conn.commit()
conn.close() conn.close()
if migrate == False: return {
return { "key": randomCharacters,
"key": randomCharacters }, 200
}, 200
else:
return {
"key": randomCharacters,
"migrate": "1"
}, 200
@app.route("/api/supersecretapi", methods=("GET", "POST")) if str(passwordchange) == "1":
def supersecretapi(): hashedpassword = generate_password_hash(newpass)
if request.method == "POST": conn = get_db_connection()
data = request.get_json() conn.execute("UPDATE users SET password = ? WHERE username = ?", (hashedpassword, username))
username = data["username"] conn.commit()
password = data["password"] conn.close()
hashedpassword = generate_password_hash(password)
conn = get_db_connection()
conn.execute("UPDATE users SET password = ? WHERE username = ?", (hashedpassword, username))
conn.commit()
conn.close()
@app.route("/api/userinfo", methods=("GET", "POST")) @app.route("/api/userinfo", methods=("GET", "POST"))
async def apiuserinfo(): async def apiuserinfo():

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"