File: //lib/python3/dist-packages/django/contrib/auth/__pycache__/tokens.cpython-310.pyc
o
3�a� � @ sT d dl m Z mZ d dlmZ d dlmZmZ d dlmZm Z G dd� d�Z
e
� ZdS )� )�datetime�time)�settings)�constant_time_compare�salted_hmac)�
base36_to_int�
int_to_base36c @ sV e Zd ZdZdZdZdZdd� Zdd� Zdd � Z ddd�Z
d
d� Zdd� Zdd� Z
dS )�PasswordResetTokenGeneratorza
Strategy object used to generate and check tokens for the password
reset mechanism.
z6django.contrib.auth.tokens.PasswordResetTokenGeneratorNc C s | j ptj| _ | jptj| _d S �N)�secretr �
SECRET_KEY� algorithm�DEFAULT_HASHING_ALGORITHM��self� r �</usr/lib/python3/dist-packages/django/contrib/auth/tokens.py�__init__ s z$PasswordResetTokenGenerator.__init__c C s | � || �| �� ��S )zi
Return a token that can be used once to do a password reset
for the given user.
)�_make_token_with_timestamp�_num_seconds�_now)r �userr r r �
make_token s z&PasswordResetTokenGenerator.make_tokenc C s� |r|sdS z|� d�\}}t|�dk }W n
ty Y dS w zt|�}W n
ty0 Y dS w t| �||�|�sGt| j||dd�|�sGdS | �� }|rb|d9 }|t|t� |�
� tj� �
� �7 }| �|�| tjkrndS dS )zP
Check that a password reset token is correct for a given user.
F�-� T)�legacyi�Q )�split�len�
ValueErrorr r r r �intr �combine�dater �min�
total_secondsr r �PASSWORD_RESET_TIMEOUT)r r �token�ts_b36�_�legacy_token�ts�nowr r r �check_token s4 ���"z'PasswordResetTokenGenerator.check_tokenFc C sH t |�}t| j| �||�| j|rdn| jd��� d d d� }d||f S )N�sha1)r r
� z%s-%s)r r �key_salt�_make_hash_valuer r
� hexdigest)r r � timestampr r&