
    k"g                     ^    d dl 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)settings)constant_time_comparesalted_hmac)base36_to_intint_to_base36c                       e Zd ZdZdZdZdZdZd Zd Z	d Z
 ee	e
      Zd Zd Z eee      Zd	 Zd
 Z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                   xs d| _         y )Nsha256)	algorithmselfs    S/var/www/html/djangosite/lib/python3.12/site-packages/django/contrib/auth/tokens.py__init__z$PasswordResetTokenGenerator.__init__   s    38    c                 >    | j                   xs t        j                  S N)_secretr   
SECRET_KEYr   s    r   _get_secretz'PasswordResetTokenGenerator._get_secret   s    ||2x222r   c                     || _         y r   )r   )r   secrets     r   _set_secretz'PasswordResetTokenGenerator._set_secret   s	    r   c                 R    | j                   t        j                  S | j                   S r   )_secret_fallbacksr   SECRET_KEY_FALLBACKSr   s    r   _get_fallbacksz*PasswordResetTokenGenerator._get_fallbacks   s&    !!)000%%%r   c                     || _         y r   )r   )r   	fallbackss     r   _set_fallbacksz*PasswordResetTokenGenerator._set_fallbacks#   s
    !*r   c                 v    | j                  || 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_nowr   )r   users     r   
make_tokenz&PasswordResetTokenGenerator.make_token(   s5    
 ..diik*KK
 	
r   c                 p   |r|sy	 |j                  d      \  }}	 t        |      }| j                  g| j                  D ]!  }t        | j                  |||      |      s! n y| j                  | 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)split
ValueErrorr   r   secret_fallbacksr   r#   r$   r%   r   PASSWORD_RESET_TIMEOUT)r   r&   tokents_b36_tsr   s          r   check_tokenz'PasswordResetTokenGenerator.check_token3   s     	C(IFA	v&B
 {{;T%:%:; 	F$//b&A 	  diik*R/83R3RR-  		
  		s"   B B) 	B&%B&)	B54B5c                     t        |      }t        | j                  | j                  ||      || j                        j                         d d d   }|d|S )N)r   r      r)   )r   r   key_salt_make_hash_valuer   	hexdigest)r   r&   	timestampr   r/   hash_strings         r   r#   z6PasswordResetTokenGenerator._make_token_with_timestampT   s[     y)!MM!!$	2nn	

 )+aC
 !+..r   c                     |j                   dn|j                   j                  dd      }|j                         }t        ||d      xs d}|j                   |j
                   | | | S )a  
        Hash the user's primary key, email (if available), and some user state
        that's sure to change after a password reset to produce a token that is
        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get_email_field_namegetattrpkpassword)r   r&   r8   login_timestampemail_fieldemails         r   r6   z,PasswordResetTokenGenerator._make_hash_valueb   sv    & & ((Qt(D 	
 //1k2.4"''4==//):9+eWMMr   c                 P    t        |t        ddd      z
  j                               S )Ni     )intr   total_seconds)r   dts     r   r$   z(PasswordResetTokenGenerator._num_seconds|   s$    B$1--<<>??r   c                 *    t        j                         S r   )r   nowr   s    r   r%   z PasswordResetTokenGenerator._now   s    ||~r   )__name__
__module____qualname____doc__r5   r   r   r   r   r   r   propertyr   r   r!   r,   r'   r2   r#   r6   r$   r%    r   r   r
   r
      sv    
 HHIG43 k;/F&
+  ?	
B/N4@r   r
   N)r   django.confr   django.utils.cryptor   r   django.utils.httpr   r   r
   default_token_generatorrS   r   r   <module>rX      s)       B :y yx 67 r   