-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
55 lines (40 loc) · 1.6 KB
/
setup.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
44
45
46
47
48
49
50
51
52
53
54
55
from passlib.hash import bcrypt
from getpass import getpass
# Load .env file
import dotenv
from dotenv import dotenv_values
config = dotenv_values(".env")
# Read value from dotenv file
# print(config["KEY"])
hasher = bcrypt.using(rounds=14) # Change default round number to be longer (more secure)
def main():
print("Welcome to the setup program for the digitech-website-2022 app.")
print("""
1. Run all options
2. Set only the MySQL username and password that the webapp uses
3. Set only the admin username and password for the webapp admin panel
4. Quit""")
choice = input(" > ")
# TODO: This looks bad, but it works. Maybe clean this up if more menu options are necessary.
if choice == "4":
exit()
if choice == "1" or choice == "2":
print("Enter MySQL username and password. NOTE: This will not be encrypted.")
set_user_and_pass("MYSQL")
if choice == "2":
exit()
print("Enter admin username and password")
set_user_and_pass("WEBAPP")
def set_user_and_pass(option):
username = input("Username: ")
password = getpass()
# Only webapp password can be encrypted.
if option == "WEBAPP":
password = hasher.hash(password)
# $2b$13$H9.qdcodBFCYOWDVMrjx/uT.fbKzYloMYD7Hj2ItDmEOnX5lw.BX.
# \__/\/ \____________________/\_____________________________/
# Alg Rounds Salt (22 char) Hash (31 char)
dotenv.set_key(".env", option + "_USERNAME", username)
dotenv.set_key(".env", option + "_PASSWORD", password)
if __name__ == '__main__':
main()