mirror of
				https://github.com/Alamantus/Lexiconga.git
				synced 2025-11-04 10:17:01 +01:00 
			
		
		
		
	Started on password reset.
This commit is contained in:
		
							parent
							
								
									a7fe6c2432
								
							
						
					
					
						commit
						02d313cb73
					
				
					 3 changed files with 52 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -3,6 +3,8 @@
 | 
			
		|||
 | 
			
		||||
require_once(SITE_LOCATION . '/php/helpers.php');
 | 
			
		||||
require_once(SITE_LOCATION . '/php/plugins/easycrypt.php');
 | 
			
		||||
require_once(SITE_LOCATION . '/php/random_string.php');
 | 
			
		||||
require_once(SITE_LOCATION . '/php/validation.php');
 | 
			
		||||
require_once(SITE_LOCATION . '/php/password_reset_validation.php');
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										38
									
								
								php/password_reset_validation.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								php/password_reset_validation.php
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
<?php
 | 
			
		||||
function Set_Password_Reset($email) {
 | 
			
		||||
    $date = date("Y-m-d H:i:s");
 | 
			
		||||
    $reset_code = Random_String(20);
 | 
			
		||||
    $query = "UPDATE `users` SET `password_reset_code`=" . $reset_code . ", `password_reset_date`='" . $date . "' WHERE `email`='" . $email . ";";
 | 
			
		||||
    $reset = query($query);
 | 
			
		||||
    
 | 
			
		||||
    if ($reset) {
 | 
			
		||||
        return true;
 | 
			
		||||
    } else {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function Check_Password_Reset($email, $code) {
 | 
			
		||||
    $date = date("Y-m-d");
 | 
			
		||||
    $daterange = "'" . $date . " 00:00:00' AND '" . $date . " 23:59:59'";
 | 
			
		||||
    $query = "SELECT * FROM `users` WHERE `email`='" . $email . "' AND `password_reset_code`='" . $code . "' AND `password_reset_date` BETWEEN " . $daterange . ";";
 | 
			
		||||
    $users = query($query);
 | 
			
		||||
    
 | 
			
		||||
    if ($users && num_rows($users) === 1) {
 | 
			
		||||
        return true;
 | 
			
		||||
    } else {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function Reset_Password($password, $email) {
 | 
			
		||||
    $query = "UPDATE `users` SET `password`=" . crypt($password, $email) . ", `password_reset_date`='0000-00-00 00:00:00' WHERE `email`='" . $email . ";";
 | 
			
		||||
    $reset = query($query);
 | 
			
		||||
    
 | 
			
		||||
    if ($reset) {
 | 
			
		||||
        return true;
 | 
			
		||||
    } else {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										12
									
								
								php/random_string.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								php/random_string.php
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
<?php
 | 
			
		||||
// Retrieved from http://stackoverflow.com/a/4356295/3508346
 | 
			
		||||
function Random_String($length = 10) {
 | 
			
		||||
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 | 
			
		||||
    $charactersLength = strlen($characters);
 | 
			
		||||
    $randomString = '';
 | 
			
		||||
    for ($i = 0; $i < $length; $i++) {
 | 
			
		||||
        $randomString .= $characters[rand(0, $charactersLength - 1)];
 | 
			
		||||
    }
 | 
			
		||||
    return $randomString;
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue