feat(core): implement secure MVP core with dictionary search, auth, and CRUD
This commit is contained in:
1 parent
4dbc53890a
commit
813d567b0e
14 files changed
+2960
No files matched your search
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
# Add project root to sys.path
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(BASE_DIR))
|
||||
|
||||
from app.database import init_db, get_db
|
||||
from app.auth import create_user, hash_password
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Manage admin users for Notes App")
|
||||
parser.add_argument("--username", "-u", required=True, help="Username")
|
||||
parser.add_argument("--password", "-p", required=True, help="Password")
|
||||
args = parser.parse_args()
|
||||
|
||||
init_db()
|
||||
|
||||
username = args.username.strip()
|
||||
password = args.password
|
||||
|
||||
pwd_hash, salt = hash_password(password)
|
||||
|
||||
with get_db() as conn:
|
||||
existing = conn.execute("SELECT id FROM users WHERE username = ?", (username,)).fetchone()
|
||||
if existing:
|
||||
conn.execute(
|
||||
"UPDATE users SET password_hash = ?, salt = ? WHERE id = ?",
|
||||
(pwd_hash, salt, existing["id"])
|
||||
)
|
||||
print(f"Password updated successfully for existing user '{username}'.")
|
||||
else:
|
||||
conn.execute(
|
||||
"INSERT INTO users (username, password_hash, salt) VALUES (?, ?, ?)",
|
||||
(username, pwd_hash, salt)
|
||||
)
|
||||
print(f"User '{username}' created successfully.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user