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