-
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathgenerate_password.py
More file actions
61 lines (51 loc) · 1.86 KB
/
generate_password.py
File metadata and controls
61 lines (51 loc) · 1.86 KB
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
56
57
58
59
60
#!/usr/bin/env python3
"""
Helper script to generate a password hash for NoteDiscovery authentication.
Usage: python generate_password.py
"""
import getpass
import bcrypt
def generate_password_hash():
"""Generate a bcrypt password hash"""
print("=== NoteDiscovery Password Hash Generator ===\n")
# Get password from user (hidden input)
password = getpass.getpass("Enter your password: ")
password_confirm = getpass.getpass("Confirm your password: ")
# Check if passwords match
if password != password_confirm:
print("\n❌ Error: Passwords do not match!")
return
if len(password) < 4:
print("\n⚠️ Warning: Password is too short! Use at least 8 characters for better security.")
proceed = input("Continue anyway? (y/N): ")
if proceed.lower() != 'y':
return
# Generate hash
print("\n🔐 Generating password hash...")
password_hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
print("\n✅ Password hash generated successfully!")
print("\n" + "="*60)
print("Copy this hash to your config.yaml:")
print("="*60)
print(f"\npassword_hash: \"{password_hash}\"")
print("\n" + "="*60)
print("\nExample config.yaml:")
print("="*60)
print("""
authentication:
enabled: true
secret_key: "your_secret_key_here"
password_hash: "{}"
session_max_age: 604800
""".format(password_hash))
print("="*60)
print("\n💡 Don't forget to also set a secret key!")
print(" Generate one with: python -c \"import secrets; print(secrets.token_hex(32))\"")
print("\n🔒 Keep your password and secret key secure!")
if __name__ == "__main__":
try:
generate_password_hash()
except KeyboardInterrupt:
print("\n\n❌ Cancelled.")
except Exception as e:
print(f"\n❌ Error: {e}")