password generator

This commit is contained in:
Anna Sudnitsina 2017-09-12 16:50:45 +03:00
parent 70b5b5498f
commit f6818c9ff3

View File

@ -2,6 +2,7 @@
import argparse
import bcrypt
import random
import sqlite3
@ -45,12 +46,16 @@ class User:
def add(self):
if self.password is None:
self.password = self._passgen()
print "Password has been generated: %s", self.password
hashed_password = bcrypt.hashpw(self.password.encode('utf-8'), bcrypt.gensalt())
self.connection["cursor"].execute(
"INSERT INTO users (name, password) VALUES (?, ?)",
(self.user, hashed_password)
)
self._commit()
try:
self.connection["cursor"].execute(
"INSERT INTO users (name, password) VALUES (?, ?)",
(self.user, hashed_password)
)
self._commit()
except sqlite3.IntegrityError:
print 'user already exists'
self._close_connection()
def delete(self):
@ -62,7 +67,8 @@ class User:
self._close_connection()
def _passgen(self):
pass
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
return ''.join(random.choice(chars) for i in range(10))
if __name__ == "__main__":