passwordhelper.py 343 Bytes
Newer Older
danmcquillan's avatar
danmcquillan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
import hashlib
import os
import base64

class PasswordHelper:
    def get_hash(self, plain):
        return hashlib.sha512(plain).hexdigest()

    def get_salt(self):
        return base64.b64encode(os.urandom(20))

    def validate_password(self, plain, salt, expected):
        return self.get_hash((salt+plain).encode('utf-8')) == expected