o
    5Îh¼  ã                   @   s    d Z ddlmZ ddlZddlZe e¡Zddlm	Z	 ddl
mZ ddlmZmZmZmZmZ ddlm  mZ ddgZG d	d„ dejƒZG d
d„ dejƒZdS )a8  passlib.handlers.mysql

MySQL 3.2.3 / OLD_PASSWORD()

    This implements Mysql's OLD_PASSWORD algorithm, introduced in version 3.2.3, deprecated in version 4.1.

    See :mod:`passlib.handlers.mysql_41` for the new algorithm was put in place in version 4.1

    This algorithm is known to be very insecure, and should only be used to verify existing password hashes.

    http://djangosnippets.org/snippets/1508/

MySQL 4.1.1 / NEW PASSWORD
    This implements Mysql new PASSWORD algorithm, introduced in version 4.1.

    This function is unsalted, and therefore not very secure against rainbow attacks.
    It should only be used when dealing with mysql passwords,
    for all other purposes, you should use a salted hash function.

    Description taken from http://dev.mysql.com/doc/refman/6.0/en/password-hashing.html
é    )Úsha1N)Úwarn)Úto_native_str)Úbascii_to_strÚunicodeÚuÚbyte_elem_valueÚstr_to_uasciiÚmysql323Úmysq41c                   @   s2   e Zd ZdZd ZdZejZe	dd„ ƒZ
dd„ ZdS )r
   a  This class implements the MySQL 3.2.3 password hash, and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
    é   c                 C   ó   |  ¡ S ©N)Úlower©ÚclsÚhash© r   új/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/passlib/handlers/mysql.pyÚ
_norm_hash>   ó   zmysql323._norm_hashc           
      C   s    t |tƒr
| d¡}d}d}d}d}d}d}|D ]+}||v rqt|ƒ}	||d@ | |	 |d	>  |@ N }||d	> |A  |@ }||	 |@ }qtd
ƒ||@ ||@ f S )Núutf-8l   ÿÿ iÿÿÿs    	i5W0PiqV4é   é?   é   z%08x%08x)Ú
isinstancer   Úencoder   r   )
ÚselfÚsecretÚMASK_32ÚMASK_31ÚWHITEÚnr1Únr2ÚaddÚcÚtmpr   r   r   Ú_calc_checksumB   s    

 zmysql323._calc_checksumN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚchecksum_sizeÚuhÚ	HEX_CHARSÚchecksum_charsÚclassmethodr   r'   r   r   r   r   r
   -   s    	
c                   @   s:   e Zd ZdZd ZedƒZejZ	dZ
edd„ ƒZdd„ ZdS )	Úmysql41a  This class implements the MySQL 4.1 password hash, and follows the :ref:`password-hash-api`.

    It has no salt and a single fixed round.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
    Ú*é(   c                 C   r   r   )Úupperr   r   r   r   r   p   r   zmysql41._norm_hashc                 C   s0   t |tƒr
| d¡}ttt|ƒ ¡ ƒ ¡ ƒ ¡ S )Nr   )r   r   r   r	   r   ÚdigestÚ	hexdigestr5   )r   r   r   r   r   r'   t   s   

zmysql41._calc_checksumN)r(   r)   r*   r+   r,   r   Ú_hash_prefixr.   r/   r0   r-   r1   r   r'   r   r   r   r   r2   ^   s    	
r2   )r+   Úhashlibr   ÚreÚloggingÚ	getLoggerr(   ÚlogÚwarningsr   Úpasslib.utilsr   Úpasslib.utils.compatr   r   r   r   r	   Úpasslib.utils.handlersÚutilsÚhandlersr.   Ú__all__ÚStaticHandlerr
   r2   r   r   r   r   Ú<module>   s    þ1