forked from winemug/omnipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_api_password.py
executable file
·37 lines (31 loc) · 1.09 KB
/
set_api_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
#!/usr/bin/python3
import hashlib
from podcomm.definitions import *
def main():
while True:
pass1 = input("Enter new password (min. 8 characters): ")
if pass1 is None or len(pass1) < 8:
print("Password is less than 8 characters long")
continue
pass2 = input("Repeat password: ")
if pass2 != pass1:
print("Passwords do not match!")
continue
try:
password = pass1.encode("utf-8")
salt = "bythepowerofgrayskull".encode("utf-8")
hash_obj = hashlib.sha256(password + salt)
key = hash_obj.digest()
with open(KEY_FILE, "w+b") as keyfile:
keyfile.write(bytes(key))
break
except Exception as e:
getLogger().error("Error while creating and saving password: %s" % e)
raise
print("Password has been set.")
print("Restarting omnipy.service for changes to take effect")
os.system("sudo systemctl restart omnipy.service")
return
if __name__ == '__main__':
configureLogging()
main()