Skip to content

Commit 1e1f5e0

Browse files
authored
Merge pull request #13 from 1to5pc/main
Merge main branch to 2-password-security
2 parents 913aea8 + 3057163 commit 1e1f5e0

File tree

5 files changed

+96
-18
lines changed

5 files changed

+96
-18
lines changed

.github/workflows/backend-test.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.10"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install flake8 pytest
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
- name: Lint with flake8
32+
run: |
33+
# stop the build if there are Python syntax errors or undefined names
34+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
- name: Test with pytest
38+
run: |
39+
pytest backendtest.py

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/1to5pc/python-auth/backend-test.yml?style=for-the-badge&label=Back%20End)
2+
![GitHub top language](https://img.shields.io/github/languages/top/1to5pc/python-auth?style=for-the-badge&logo=python)
3+
14
# A "simple" and easy to use python based authentication system
2-
## Test results:
3-
![Test Parmeter](https://github.com/1to5pc/python-auth/actions/workflows/python-app.yml/badge.svg)

test.py backendtest.py

File renamed without changes.

config.cfg config.ini

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# This is the default config
2-
# * Not yet implemented
2+
# Algorithm switching not yet implemented
33
# WARNING: DO NOT CHANGE ENCRYPTION ALGORITHMS AFTER INITAL SETUP. MULTIPLE ENCYRPTION STANDARDS ARE NOT SUPPORTED SIMULTANEOUSLY
4+
# Salt size should be in characters. '0' disables salting.
45

56
[Config]
67
quiet = True
7-
alg = sha256 # Can be either SHA256 or *bycrypt/argon2*
8+
alg = sha256
89

10+
[Salt]
11+
saltSize = 8
912

1013
[Debugging]

usrcheck.py

+49-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
def configRead():
2+
import configparser
3+
config = configparser.ConfigParser()
4+
config.read('config.ini')
5+
try:
6+
quiet = config['Config']['quiet']
7+
quiet = quiet.lower() in ("true")
8+
except KeyError:
9+
quiet = False
10+
try:
11+
alg = config['Config']['alg']
12+
alg = str(quiet).lower()
13+
except KeyError:
14+
print("ERROR: Algorithm not defined. Reverting to SHA256")
15+
alg = 'sha256'
16+
try:
17+
saltSize = config['Salt']['saltSize']
18+
saltSize = int(saltSize)
19+
except KeyError:
20+
saltSize = 8
21+
print("ERROR: saltSize not defined or not integer. Reverting to 8")
22+
return quiet,alg,saltSize
23+
24+
def salter(pswd,saltsize):
25+
import string
26+
import secrets
27+
pass
28+
129
def init_usrs(nUsr):
230
import hashlib
331
usrlist=[]
@@ -26,11 +54,14 @@ def save_users(usrlist,overWrite):
2654
saveFile = open("usrlist", "w")
2755
else:
2856
saveFile = open("usrlist", "a")
29-
for x in range(len(usrlist)):
30-
if (x-2)<len(usrlist):
31-
saveFile.write(str(usrlist[x][0])+","+str(usrlist[x][1])+",")
32-
else:
33-
saveFile.write(str(usrlist[x][0])+","+str(usrlist[x][1]))
57+
if len(usrlist)>0:
58+
for x in range(len(usrlist)):
59+
if (x-2)<len(usrlist):
60+
saveFile.write(str(usrlist[x][0])+","+str(usrlist[x][1])+",")
61+
else:
62+
saveFile.write(str(usrlist[x][0])+","+str(usrlist[x][1]))
63+
else:
64+
saveFile.write('')
3465
saveFile.close()
3566

3667
def usr_check(usrn,pswd,usrlist):
@@ -78,7 +109,7 @@ def login_init(usrname,pswd,overWrite,quiet):
78109
else:
79110
newFile=False
80111
while True:
81-
nUsr=input("Enter the number of users to initialize: ")
112+
nUsr=input("Enter the number of users to initialize ('0' Clears the database): ")
82113
try:
83114
nUsr=int(nUsr)
84115
break
@@ -87,43 +118,47 @@ def login_init(usrname,pswd,overWrite,quiet):
87118
if nUsr>0:
88119
usrlist=init_usrs(nUsr)
89120
save_users(usrlist,newFile)
121+
elif nUsr==0:
122+
save_users([],True)
90123
else:
91124
usrlist = load_users()
92125
Ufound,Pfound=usr_check(usrname,pswd,usrlist)
93126
loginSt=login_status(Ufound,Pfound,quiet)
94127
return loginSt
95128

96129

97-
def Auth_test():
130+
def Auth_test(quiet):
98131
import os
132+
configRead()
99133
try:
100134
print("[Authentication Test]".center(os.get_terminal_size().columns))
101135
except OSError:
102136
print("[Authentication Test]")
103137
usr=input("Input username: ")
104138
pswd=input("Input password: ")
105-
if input("Enable quiet mode? [y/N]").upper() == "Y":
106-
quiet=True
107-
else:
108-
quiet=False
139+
# if input("Enable quiet mode? [y/N]").upper() == "Y":
140+
# quiet=True
141+
# else:
142+
# quiet=False
109143
loginSuccess=login_init(usr,pswd,False,quiet)
110144
print("Login success status:", loginSuccess)
111145

112146
def main_menu():
147+
quiet,alg,saltSize=configRead()
113148
print("\n--- Main Menu ---")
114149
print("0. Initialize user accounts")
115150
print("1. Test Authentication")
116151
print("2. Exit")
117152
choice = input("Enter your choice: ")
118153
if choice == '0':
119-
login_init('','',True,False)
154+
login_init('','',True,quiet)
120155
elif choice == '1':
121-
Auth_test()
156+
Auth_test(quiet)
122157
elif choice == '2':
123158
print("Exiting program.")
124159
exit()
125160
else:
126-
print("Invalid choice. Please enter 1 or 2.")
161+
print("Invalid choice. Please enter 0, 1 or 2.")
127162
main_menu()
128163

129164
if __name__ == "__main__":

0 commit comments

Comments
 (0)