Update for public https://habr.com/post/421887/
This commit is contained in:
37
myapp/lib/passwd.py
Normal file
37
myapp/lib/passwd.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__copyright__ = '(c) RemiZOffAlex'
|
||||
__license__ = 'MIT'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
import random
|
||||
import hashlib
|
||||
|
||||
from .. import app
|
||||
|
||||
def pwgen(length=15, hex=False):
|
||||
"""
|
||||
Генератор пароля
|
||||
"""
|
||||
keylist='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
if hex:
|
||||
keylist='0123456789ABCDEF'
|
||||
password=[]
|
||||
|
||||
while len(password) < length:
|
||||
a_char = random.choice(keylist)
|
||||
password.append(a_char)
|
||||
return ''.join(password)
|
||||
|
||||
def get_hash_password(password, salt = None):
|
||||
"""
|
||||
Получить хеш пароля SHA-512
|
||||
"""
|
||||
if salt == None:
|
||||
salt = uuid.uuid4().hex
|
||||
text = password.encode('utf-8') + salt.encode('utf-8')
|
||||
h = hashlib.sha512()
|
||||
h.update(text)
|
||||
return str(h.hexdigest())
|
||||
Reference in New Issue
Block a user