mirror of
https://github.com/sigmasternchen/Diary
synced 2025-03-15 15:18:57 +00:00
Users can be added now with adduser.py and the passwords are being
hashed!
This commit is contained in:
parent
e79f0988a7
commit
83bf6fe765
2 changed files with 20 additions and 2 deletions
15
adduser.py
Normal file
15
adduser.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env python2.7
|
||||||
|
|
||||||
|
import getpass
|
||||||
|
from database import db_session as db
|
||||||
|
|
||||||
|
passprompt=lambda:(getpass.getpass('Password: '),getpass.getpass('Retype password: '))
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
username=raw_input('Username: ')
|
||||||
|
p1,p2=passprompt()
|
||||||
|
while p1!=p2:
|
||||||
|
print 'Passwords do not match!'
|
||||||
|
p1,p2=passprompt()
|
||||||
|
db.add(User(username,p1))
|
||||||
|
db.commit()
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python2.7
|
||||||
|
|
||||||
import datetime
|
import datetime,bcrypt
|
||||||
|
|
||||||
from sqlalchemy import Column,Integer,String,Date
|
from sqlalchemy import Column,Integer,String,Date
|
||||||
from database import Base
|
from database import Base
|
||||||
|
@ -13,7 +13,10 @@ class User(Base):
|
||||||
|
|
||||||
def __init__(self,username,password):
|
def __init__(self,username,password):
|
||||||
self.username=username
|
self.username=username
|
||||||
self.password=password
|
self.password=bcrypt.hashpw(password.encode(),bcrypt.gensalt().encode())
|
||||||
|
|
||||||
|
def checkpass(self,password):
|
||||||
|
return self.password==bcrypt.hashpw(password.encode(),self.password.encode())
|
||||||
|
|
||||||
class Diary(Base):
|
class Diary(Base):
|
||||||
__tablename__='diaries'
|
__tablename__='diaries'
|
||||||
|
|
Loading…
Reference in a new issue