-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathreset_admin.py
More file actions
123 lines (101 loc) · 2.59 KB
/
reset_admin.py
File metadata and controls
123 lines (101 loc) · 2.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
import hashlib
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
from werkzeug.security import generate_password_hash
# 确保数据目录存在
data_dir = os.path.join(os.getcwd(), 'data')
db_path = os.path.join(data_dir, 'lottery_system.db')
if not os.path.exists(db_path):
print(f"错误: 数据库文件不存在: {db_path}")
exit(1)
# 连接数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# 生成与Werkzeug兼容的密码哈希
def generate_password_hash(password):
"""生成与Werkzeug兼容的密码哈希"""
# 使用pbkdf2:sha256方法,与Werkzeug默认方法兼容
method = 'pbkdf2:sha256:150000'
salt = os.urandom(8).hex()
h = hashlib.pbkdf2_hmac('sha256', password.encode(), salt.encode(), 150000)
hash_value = h.hex()
return f"{method}${salt}${hash_value}"
# 新密码
new_password = 'admin123'
password_hash = generate_password_hash(new_password)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
import hashlib
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
from werkzeug.security import generate_password_hash
# 确保数据目录存在
data_dir = os.path.join(os.getcwd(), 'data')
db_path = os.path.join(data_dir, 'lottery_system.db')
if not os.path.exists(db_path):
print(f"错误: 数据库文件不存在: {db_path}")
exit(1)
# 连接数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
import hashlib
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重置管理员密码脚本
"""
import os
import sqlite3
from werkzeug.security import generate_password_hash
# 确保数据目录存在
data_dir = os.path.join(os.getcwd(), 'data')
db_path = os.path.join(data_dir, 'lottery_system.db')
if not os.path.exists(db_path):
print(f"错误: 数据库文件不存在: {db_path}")
exit(1)
# 连接数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# 新密码
new_password = 'admin123'
password_hash = generate_password_hash(new_password)
# 更新管理员密码
cursor.execute('''
UPDATE user
SET password_hash = ?
WHERE username = 'admin'
''', (password_hash,))
# 提交更改并关闭连接
conn.commit()
conn.close()
print(f"✓ 管理员密码已重置为: {new_password}")
print("请立即登录并修改此默认密码")