server/utils.py
changeset 10681 4383f5a30504
parent 10678 77333ec71fab
child 10907 9ae707db5265
equal deleted inserted replaced
10680:1b4df4b3cd9a 10681:4383f5a30504
    62 
    62 
    63 def crypt_password(passwd, salt=None):
    63 def crypt_password(passwd, salt=None):
    64     """return the encrypted password using the given salt or a generated one
    64     """return the encrypted password using the given salt or a generated one
    65     """
    65     """
    66     if salt is None:
    66     if salt is None:
    67         return _CRYPTO_CTX.encrypt(passwd)
    67         return _CRYPTO_CTX.encrypt(passwd).encode('ascii')
    68     # empty hash, accept any password for backwards compat
    68     # empty hash, accept any password for backwards compat
    69     if salt == '':
    69     if salt == '':
    70         return salt
    70         return salt
    71     try:
    71     try:
    72         if _CRYPTO_CTX.verify(passwd, salt):
    72         if _CRYPTO_CTX.verify(passwd, salt):
    73             return salt
    73             return salt
    74     except ValueError: # e.g. couldn't identify hash
    74     except ValueError: # e.g. couldn't identify hash
    75         pass
    75         pass
    76     # wrong password
    76     # wrong password
    77     return ''
    77     return b''
    78 
    78 
    79 
    79 
    80 def eschema_eid(cnx, eschema):
    80 def eschema_eid(cnx, eschema):
    81     """get eid of the CWEType entity for the given yams type. You should use
    81     """get eid of the CWEType entity for the given yams type. You should use
    82     this because when schema has been loaded from the file-system, not from the
    82     this because when schema has been loaded from the file-system, not from the