-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sqlite3 | ||
|
||
import argon2 | ||
from flask_login import UserMixin | ||
|
||
|
||
class AdminUser(UserMixin): | ||
def __init__(self, username, password=None): | ||
self.username = username | ||
if password: | ||
self.hashed_password = argon2.PasswordHasher().hash(password) | ||
self.id = 1 | ||
|
||
def check_password(self, password): | ||
connection = sqlite3.connect("database.db") | ||
cursor = connection.cursor() | ||
|
||
cursor.execute("SELECT password FROM admins WHERE username = ?", (self.username,)) | ||
result = cursor.fetchone() | ||
connection.close() | ||
if not result: | ||
print("USERNAME IS NOT FOUND") | ||
return False | ||
try: | ||
print("Verify hash result:", argon2.PasswordHasher().verify(result[0], password)) | ||
return True | ||
except argon2.exceptions.VerifyMismatchError: | ||
print("PASSWORD IS INCORRECT") | ||
return False | ||
|
||
def create_user(self): | ||
connection = sqlite3.connect("database.db") | ||
cursor = connection.cursor() | ||
cursor.execute("INSERT OR REPLACE INTO admins (id, username, password) VALUES (1, ?, ?)", | ||
(self.username, self.hashed_password)) | ||
connection.commit() | ||
connection.close() | ||
|
||
def is_authenticated(self): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ flask-login | |
schedule | ||
pylint | ||
pycodestyle | ||
gunicorn==20.0.4 | ||
gunicorn==20.0.4 | ||
argon2-cffi |