This commit is contained in:
hex
2025-05-19 20:34:51 -07:00
parent 11f14f5048
commit c5a60a6c13
8 changed files with 756 additions and 8 deletions

View File

@@ -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)