
    hW                     b    d dl m Z mZ d dlmZ d dlmZmZ d dlmZm	Z	  G d d      Z
 e
       Zy)    )datetimetime)settings)constant_time_comparesalted_hmac)base36_to_intint_to_base36c                   \    e Zd ZdZdZdZej                  Zd Z	d Z
d ZddZd Zd	 Zd
 Zy)PasswordResetTokenGeneratorza
    Strategy object used to generate and check tokens for the password
    reset mechanism.
    z6django.contrib.auth.tokens.PasswordResetTokenGeneratorNc                 J    | j                   xs t        j                  | _         y N)	algorithmr   DEFAULT_HASHING_ALGORITHMselfs    ]/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/django/contrib/auth/tokens.py__init__z$PasswordResetTokenGenerator.__init__   s     M8+M+M    c                 `    | j                  || j                  | j                                     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   users     r   
make_tokenz&PasswordResetTokenGenerator.make_token   s(    
 ..tT5F5Ftyy{5STTr   c                 6   |r|sy	 |j                  d      \  }}t        |      dk  }	 t        |      }t	        | j                  ||      |      st	        | j                  ||d      |      sy| j                         }|rT|dz  }|t        |t        j                  |j                         t        j                        z
  j                               z  }| j                  |      |z
  t        j                   kD  ryy# t        $ r Y yw xY w# t        $ r Y yw xY w)zP
        Check that a password reset token is correct for a given user.
        F-   T)legacyiQ )splitlen
ValueErrorr   r   r   r   intr   combinedater   mintotal_secondsr   r   PASSWORD_RESET_TIMEOUT)r   r   tokents_b36_legacy_tokentsnows           r   check_tokenz'PasswordResetTokenGenerator.check_token   s    	C(IFAv;?L	v&B
 %T%D%DT2%NPUV )//b/F  iik,B#sX--chhj$((CCRRTUUBc"R'8+J+JJ;  		
  		s"   "C= D =	D	D		DDc                     t        |      }t        | j                  | j                  ||      | j                  |rdn| j
                        j                         d d d   }|d|S )Nsha1)secretr      r   )r	   r   key_salt_make_hash_valuer1   r   	hexdigest)r   r   	timestampr   r)   hash_strings         r   r   z6PasswordResetTokenGenerator._make_token_with_timestampG   sd     y)!MM!!$	2;; !'fDNN
 )+cc !+..r   c                     |j                   dn|j                   j                  dd      }t        |j                        |j                  z   t        |      z   t        |      z   S )a  
        Hash the user's primary key and some user state that's sure to change
        after a password reset to produce a token that invalidated when it's
        used:
        1. The password field will change upon a password reset (even if the
           same password is chosen, due to password salting).
        2. The last_login field will usually be updated very shortly after
           a password reset.
        Failing those things, settings.PASSWORD_RESET_TIMEOUT eventually
        invalidates the token.

        Running this data through salted_hmac() prevents password cracking
        attempts using the reset token, provided the secret isn't compromised.
        N r   )microsecondtzinfo)
last_loginreplacestrpkpassword)r   r   r6   login_timestamps       r   r4   z,PasswordResetTokenGenerator._make_hash_valueV   sT    " !% 7"T__=T=Tabko=T=p477|dmm+c/.BBS^SSr   c                 P    t        |t        ddd      z
  j                               S )Ni     )r"   r   r&   )r   dts     r   r   z(PasswordResetTokenGenerator._num_secondsj   s$    B$1--<<>??r   c                 *    t        j                         S r   )r   r-   r   s    r   r   z PasswordResetTokenGenerator._nowm   s    ||~r   )F)__name__
__module____qualname____doc__r3   r   r   
SECRET_KEYr1   r   r   r.   r   r4   r   r    r   r   r   r      sG     HHI  FN
U(T/T(@r   r   N)r   r   django.confr   django.utils.cryptor   r   django.utils.httpr   r	   r   default_token_generatorrK   r   r   <module>rP      s)    #   B :g gT 67 r   