forked from renamedquery/youtube-dl-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-user-password.py
43 lines (30 loc) · 1.47 KB
/
edit-user-password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#this script assumes that anybody who has access to the console is an admin
#import statements
import sqlite3, getpass
import werkzeug.security as WZS
from config import DATABASE_PATH
#connect to the database
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
#get the account that they want to change the password for
USERNAME = str(input('What account do you want to change tha password for? '))
#check that the user exists in the database
DATABASE_CURSOR.execute('SELECT * FROM users WHERE username = ?', (USERNAME,))
#check if there is more than 0 rows (user exists)
if (not len(DATABASE_CURSOR.fetchall()) > 0):
#tell the user that there were no matching users, then quit
print('No users were found with that username. Exiting.')
exit()
#get the new password for the account
password = str(getpass.getpass(prompt = 'New password for {}: '.format(USERNAME)))
passwordConfirm = str(getpass.getpass(prompt = 'Confirm new password for {}: '.format(USERNAME)))
#check that the account passwords match
if (password != passwordConfirm):
#tell the user that the two passwords dont match, then quit
print('The passwords entered did not match. Exiting.')
exit()
#update the password
DATABASE_CONNECTION.execute('UPDATE users SET password = ? WHERE username = ?', (WZS.generate_password_hash(password), USERNAME))
DATABASE_CONNECTION.commit()
#tell the user that it was successful
print('Successfully changed account password.')