Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Trevor Austin
/
mpcs-52553-austin-winter-2021
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
65c1fe82
authored
Feb 17, 2021
by
Trevor Austin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use BCrypt with Salt
parent
49c4c9dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
8 deletions
week_6/examples/passwords/app.py
week_6/examples/passwords/migrations/20200304T184700-create_tables.sql
week_6/examples/passwords/app.py
View file @
65c1fe82
from
flask
import
Flask
,
render_template
,
request
,
jsonify
from
functools
import
wraps
import
mysql.connector
# pip3 install mysql-connector
#
import bcrypt
import
bcrypt
import
configparser
import
io
...
...
@@ -28,7 +28,8 @@ def signup ():
print
(
body
)
username
=
body
[
'username'
]
password
=
body
[
'password'
]
password
=
body
[
'password'
]
.
encode
(
'utf-8'
)
hashed
=
bcrypt
.
hashpw
(
password
,
bcrypt
.
gensalt
())
connection
=
mysql
.
connector
.
connect
(
user
=
DB_USERNAME
,
database
=
DB_NAME
,
password
=
DB_PASSWORD
)
cursor
=
connection
.
cursor
()
...
...
@@ -36,7 +37,7 @@ def signup ():
query
=
"INSERT into users (username, password) VALUES (
%
s,
%
s)"
try
:
cursor
.
execute
(
query
,
(
username
,
passwor
d
))
cursor
.
execute
(
query
,
(
username
,
hashe
d
))
connection
.
commit
()
return
{}
except
Exception
as
e
:
...
...
@@ -63,12 +64,13 @@ def login ():
try
:
cursor
.
execute
(
query
,
(
username
,))
savedPassword
=
cursor
.
fetchone
()[
0
]
hashed
=
cursor
.
fetchone
()[
0
]
print
(
password
)
print
(
savedPasswor
d
)
print
(
hashe
d
)
if
password
==
savedPassword
:
if
bcrypt
.
checkpw
(
password
.
encode
(
'utf-8'
),
hashed
.
encode
(
'utf-8'
))
:
return
{}
return
{},
404
except
Exception
as
e
:
...
...
week_6/examples/passwords/migrations/20200304T184700-create_tables.sql
View file @
65c1fe82
...
...
@@ -2,6 +2,5 @@
create
table
users
(
username
VARCHAR
(
40
)
PRIMARY
KEY
,
password
VARCHAR
(
20
)
-- password BINARY(60) NOT NULL
password
VARCHAR
(
60
)
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment