admin
This commit is contained in:
@@ -1,5 +1,43 @@
|
||||
from . import db
|
||||
from datetime import datetime
|
||||
import hashlib
|
||||
|
||||
class AdminConfig(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
password_hash = db.Column(db.String(64), nullable=False)
|
||||
last_updated = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
@classmethod
|
||||
def check_password(cls, password):
|
||||
"""Check if the provided password matches the stored hash"""
|
||||
admin = cls.query.first()
|
||||
if not admin:
|
||||
return False
|
||||
|
||||
# Create hash from input password
|
||||
hash_input = hashlib.sha256(password.encode()).hexdigest()
|
||||
|
||||
# Compare with stored hash
|
||||
return hash_input == admin.password_hash
|
||||
|
||||
@classmethod
|
||||
def set_password(cls, password):
|
||||
"""Set a new admin password"""
|
||||
admin = cls.query.first()
|
||||
|
||||
# Create hash from the password
|
||||
password_hash = hashlib.sha256(password.encode()).hexdigest()
|
||||
|
||||
if admin:
|
||||
admin.password_hash = password_hash
|
||||
admin.last_updated = datetime.utcnow()
|
||||
else:
|
||||
admin = cls(password_hash=password_hash)
|
||||
db.session.add(admin)
|
||||
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
|
||||
class Game(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
Reference in New Issue
Block a user