diff --git a/app/components/Login.tsx b/app/components/Login.tsx index c766f09..1d8a4e6 100644 --- a/app/components/Login.tsx +++ b/app/components/Login.tsx @@ -55,9 +55,12 @@ const Login: React.FC = () => { const savedAccountName = localStorage.getItem('accountName'); // Check if savedAccountName or savedAccountEmail is not null before passing to checkCredentials - const accountIdentifier = savedAccountName || savedAccountEmail; + var accountIdentifier = savedAccountName || savedAccountEmail; + if (!accountIdentifier) { + accountIdentifier = accountName + } - if (accountIdentifier && password === savedAccountPassword) { + if (accountIdentifier && password) { const success = await checkCredentials(accountIdentifier, password); if (success) { setIsLoggedIn(true); // Successful login diff --git a/py/db.py b/py/db.py index a20cd84..778c6c7 100644 --- a/py/db.py +++ b/py/db.py @@ -9,9 +9,13 @@ class DB: self.database = {} def ensure_username(self, data): - if hasattr(data, 'username'): + print(data) + print(self.database) + if 'username' in data: + print("usr") return data.get('username') - elif hasattr(data, 'email'): + elif 'email' in data: + print("email") for index, entry in self.database: if entry.get('email') == data.get('email'): return index @@ -71,10 +75,13 @@ class DB: username = self.ensure_username(data) password = data.get('password') if username not in self.database: + print("no username") + print(username) return False stored_hashed_password = self.database[username]["hashed_password"] entered_hashed_password = self.hash_password(password) + print(stored_hashed_password == entered_hashed_password) return stored_hashed_password == entered_hashed_password def get_data(self, data): @@ -82,7 +89,7 @@ class DB: if not self.check_credentials(data): return None - send_back = self.database(username).get('data') + send_back = self.database[username].get('data') return send_back def save_database(self):