Welcome to mirror list, hosted at ThFree Co, Russian Federation.

password.py « util « bareos - github.com/bareos/python-bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99def1255d10d80cb7f621d99d2ca159aa972966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Class to handle Bareos passwords.
"""

import hashlib

class Password(object):

    def __init__(self, password=None):
        self.password_md5 = None
        self.set_plaintext(password)

    def set_plaintext(self, password):
        self.password_plaintext = bytearray(password, 'utf-8')
        self.set_md5(self.__plaintext2md5(password))

    def set_md5(self, password):
        self.password_md5 = password

    def plaintext(self):
        return self.password_plaintext

    def md5(self):
        return self.password_md5

    @staticmethod
    def __plaintext2md5(password):
        '''
        md5 the password and return the hex style
        '''
        md5 = hashlib.md5()
        md5.update(bytearray(password, 'utf-8'))
        return md5.hexdigest()