|
|
@ -1,7 +1,7 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
class Users{
|
|
|
|
class Users{
|
|
|
|
|
|
|
|
|
|
|
|
function add_user(){
|
|
|
|
public function add_user(){
|
|
|
|
// check if values exist
|
|
|
|
// check if values exist
|
|
|
|
if ( isset( $_POST["Username"] ) and isset( $_POST["Password"] ) and isset( $_POST["Email"] ) )
|
|
|
|
if ( isset( $_POST["Username"] ) and isset( $_POST["Password"] ) and isset( $_POST["Email"] ) )
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -66,167 +66,168 @@ class Users{
|
|
|
|
$pageElements['TAC_ERROR'] = 'TRUE';
|
|
|
|
$pageElements['TAC_ERROR'] = 'TRUE';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $pageElements;
|
|
|
|
return $pageElements;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Function checkUser
|
|
|
|
* Function checkUser
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @takes $username
|
|
|
|
* @takes $username
|
|
|
|
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
|
|
|
* @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function checkUser( $username )
|
|
|
|
public function checkUser( $username )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( isset( $username ) ){
|
|
|
|
if ( isset( $username ) ){
|
|
|
|
if ( strlen( $username ) > 12 ){
|
|
|
|
if ( strlen( $username ) > 12 ){
|
|
|
|
return "Username must be no more than 12 characters.";
|
|
|
|
return "Username must be no more than 12 characters.";
|
|
|
|
}elseif ( strlen( $username ) < 5 ){
|
|
|
|
}elseif ( strlen( $username ) < 5 ){
|
|
|
|
return "Username must be 5 or more characters.";
|
|
|
|
return "Username must be 5 or more characters.";
|
|
|
|
}elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){
|
|
|
|
}elseif ( !preg_match( '/^[a-z0-9\.]*$/', $username ) ){
|
|
|
|
return "Username can only contain numbers and letters.";
|
|
|
|
return "Username can only contain numbers and letters.";
|
|
|
|
}elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array(
|
|
|
|
}elseif ( sql :: db_query( "SELECT COUNT(*) FROM {users} WHERE name = :name", array(
|
|
|
|
':name' => $username
|
|
|
|
':name' => $username
|
|
|
|
) ) -> fetchField() ){
|
|
|
|
) ) -> fetchField() ){
|
|
|
|
return "Username " . $username . " is in use.";
|
|
|
|
return "Username " . $username . " is in use.";
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return "success";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
return "success";
|
|
|
|
return "success";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "fail";
|
|
|
|
}else{
|
|
|
|
}
|
|
|
|
return "success";
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* Function checkPassword
|
|
|
|
return "fail";
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @takes $pass
|
|
|
|
/**
|
|
|
|
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
|
|
|
* Function checkPassword
|
|
|
|
*/
|
|
|
|
*
|
|
|
|
public function checkPassword( $pass )
|
|
|
|
* @takes $pass
|
|
|
|
{
|
|
|
|
* @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned
|
|
|
|
if ( isset( $pass ) ){
|
|
|
|
*/
|
|
|
|
if ( strlen( $pass ) > 20 ){
|
|
|
|
public function checkPassword( $pass )
|
|
|
|
return "Password must be no more than 20 characters.";
|
|
|
|
{
|
|
|
|
}elseif ( strlen( $pass ) < 5 ){
|
|
|
|
if ( isset( $pass ) ){
|
|
|
|
return "Password must be more than 5 characters.";
|
|
|
|
if ( strlen( $pass ) > 20 ){
|
|
|
|
}else{
|
|
|
|
return "Password must be no more than 20 characters.";
|
|
|
|
return "success";
|
|
|
|
}elseif ( strlen( $pass ) < 5 ){
|
|
|
|
}
|
|
|
|
return "Password must be more than 5 characters.";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "fail";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Function confirmPassword
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @takes $pass
|
|
|
|
|
|
|
|
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function confirmPassword()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){
|
|
|
|
|
|
|
|
return "Passwords do not match.";
|
|
|
|
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
return "success";
|
|
|
|
return "success";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "fail";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "fail";
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* Function checkEmail
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Function confirmPassword
|
|
|
|
* @takes $email
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @takes $pass
|
|
|
|
*/
|
|
|
|
* @return string Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"]
|
|
|
|
public function checkEmail( $email )
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
public function confirmPassword()
|
|
|
|
if ( isset( $email ) ){
|
|
|
|
{
|
|
|
|
if ( !validEmail( $email ) ){
|
|
|
|
if ( ( $_POST["Password"] ) != ( $_POST["ConfirmPass"] ) ){
|
|
|
|
return "Email address is not valid.";
|
|
|
|
return "Passwords do not match.";
|
|
|
|
}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(
|
|
|
|
}else{
|
|
|
|
':mail' => $email
|
|
|
|
return "success";
|
|
|
|
) ) -> fetchField() ){
|
|
|
|
}
|
|
|
|
return "Email is in use.";
|
|
|
|
return "fail";
|
|
|
|
}else{
|
|
|
|
}
|
|
|
|
return "success";
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* Function checkEmail
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @takes $email
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function checkEmail( $email )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( isset( $email ) ){
|
|
|
|
|
|
|
|
if ( !validEmail( $email ) ){
|
|
|
|
|
|
|
|
return "Email address is not valid.";
|
|
|
|
|
|
|
|
}elseif ( db_query( "SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(
|
|
|
|
|
|
|
|
':mail' => $email
|
|
|
|
|
|
|
|
) ) -> fetchField() ){
|
|
|
|
|
|
|
|
return "Email is in use.";
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
return "success";
|
|
|
|
return "success";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "fail";
|
|
|
|
}else{
|
|
|
|
}
|
|
|
|
return "success";
|
|
|
|
public function validEmail( $email )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
return "fail";
|
|
|
|
$isValid = true;
|
|
|
|
}
|
|
|
|
$atIndex = strrpos( $email, "@" );
|
|
|
|
public function validEmail( $email )
|
|
|
|
if ( is_bool( $atIndex ) && !$atIndex ){
|
|
|
|
{
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = true;
|
|
|
|
}else{
|
|
|
|
$atIndex = strrpos( $email, "@" );
|
|
|
|
$domain = substr( $email, $atIndex + 1 );
|
|
|
|
if ( is_bool( $atIndex ) && !$atIndex ){
|
|
|
|
$local = substr( $email, 0, $atIndex );
|
|
|
|
$isValid = false;
|
|
|
|
$localLen = strlen( $local );
|
|
|
|
}else{
|
|
|
|
$domainLen = strlen( $domain );
|
|
|
|
$domain = substr( $email, $atIndex + 1 );
|
|
|
|
if ( $localLen < 1 || $localLen > 64 ){
|
|
|
|
$local = substr( $email, 0, $atIndex );
|
|
|
|
// local part length exceeded
|
|
|
|
$localLen = strlen( $local );
|
|
|
|
$isValid = false;
|
|
|
|
$domainLen = strlen( $domain );
|
|
|
|
}else if ( $domainLen < 1 || $domainLen > 255 ){
|
|
|
|
if ( $localLen < 1 || $localLen > 64 ){
|
|
|
|
// domain part length exceeded
|
|
|
|
// local part length exceeded
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = false;
|
|
|
|
}else if ( $local[0] == '.' || $local[$localLen - 1] == '.' ){
|
|
|
|
}else if ( $domainLen < 1 || $domainLen > 255 ){
|
|
|
|
// local part starts or ends with '.'
|
|
|
|
// domain part length exceeded
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = false;
|
|
|
|
}else if ( preg_match( '/\\.\\./', $local ) ){
|
|
|
|
}else if ( $local[0] == '.' || $local[$localLen - 1] == '.' ){
|
|
|
|
// local part has two consecutive dots
|
|
|
|
// local part starts or ends with '.'
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = false;
|
|
|
|
}else if ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ){
|
|
|
|
}else if ( preg_match( '/\\.\\./', $local ) ){
|
|
|
|
// character not valid in domain part
|
|
|
|
// local part has two consecutive dots
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = false;
|
|
|
|
}else if ( preg_match( '/\\.\\./', $domain ) ){
|
|
|
|
}else if ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ){
|
|
|
|
// domain part has two consecutive dots
|
|
|
|
// character not valid in domain part
|
|
|
|
$isValid = false;
|
|
|
|
$isValid = false;
|
|
|
|
}else if ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\", "", $local ) ) ){
|
|
|
|
}else if ( preg_match( '/\\.\\./', $domain ) ){
|
|
|
|
// character not valid in local part unless
|
|
|
|
// domain part has two consecutive dots
|
|
|
|
// local part is quoted
|
|
|
|
$isValid = false;
|
|
|
|
if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ){
|
|
|
|
}else if ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\", "", $local ) ) ){
|
|
|
|
$isValid = false;
|
|
|
|
// character not valid in local part unless
|
|
|
|
}
|
|
|
|
// local part is quoted
|
|
|
|
}
|
|
|
|
if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ){
|
|
|
|
if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ){
|
|
|
|
$isValid = false;
|
|
|
|
// domain not found in DNS
|
|
|
|
|
|
|
|
$isValid = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $isValid;
|
|
|
|
if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ){
|
|
|
|
}
|
|
|
|
// domain not found in DNS
|
|
|
|
public function generateSALT( $length = 2 )
|
|
|
|
$isValid = false;
|
|
|
|
{
|
|
|
|
|
|
|
|
// start with a blank salt
|
|
|
|
|
|
|
|
$salt = "";
|
|
|
|
|
|
|
|
// define possible characters - any character in this string can be
|
|
|
|
|
|
|
|
// picked for use in the salt, so if you want to put vowels back in
|
|
|
|
|
|
|
|
// or add special characters such as exclamation marks, this is where
|
|
|
|
|
|
|
|
// you should do it
|
|
|
|
|
|
|
|
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
|
|
|
|
|
|
|
|
// we refer to the length of $possible a few times, so let's grab it now
|
|
|
|
|
|
|
|
$maxlength = strlen( $possible );
|
|
|
|
|
|
|
|
// check for length overflow and truncate if necessary
|
|
|
|
|
|
|
|
if ( $length > $maxlength ){
|
|
|
|
|
|
|
|
$length = $maxlength;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set up a counter for how many characters are in the salt so far
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
return $isValid;
|
|
|
|
// add random characters to $salt until $length is reached
|
|
|
|
}
|
|
|
|
while ( $i < $length ){
|
|
|
|
public function generateSALT( $length = 2 )
|
|
|
|
// pick a random character from the possible ones
|
|
|
|
{
|
|
|
|
$char = substr( $possible, mt_rand( 0, $maxlength - 1 ), 1 );
|
|
|
|
// start with a blank salt
|
|
|
|
// have we already used this character in $salt?
|
|
|
|
$salt = "";
|
|
|
|
if ( !strstr( $salt, $char ) ){
|
|
|
|
// define possible characters - any character in this string can be
|
|
|
|
// no, so it's OK to add it onto the end of whatever we've already got...
|
|
|
|
// picked for use in the salt, so if you want to put vowels back in
|
|
|
|
$salt .= $char;
|
|
|
|
// or add special characters such as exclamation marks, this is where
|
|
|
|
// ... and increase the counter by one
|
|
|
|
// you should do it
|
|
|
|
$i++;
|
|
|
|
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
|
|
|
|
}
|
|
|
|
// we refer to the length of $possible a few times, so let's grab it now
|
|
|
|
|
|
|
|
$maxlength = strlen( $possible );
|
|
|
|
|
|
|
|
// check for length overflow and truncate if necessary
|
|
|
|
|
|
|
|
if ( $length > $maxlength ){
|
|
|
|
|
|
|
|
$length = $maxlength;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up a counter for how many characters are in the salt so far
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
// add random characters to $salt until $length is reached
|
|
|
|
|
|
|
|
while ( $i < $length ){
|
|
|
|
|
|
|
|
// pick a random character from the possible ones
|
|
|
|
|
|
|
|
$char = substr( $possible, mt_rand( 0, $maxlength - 1 ), 1 );
|
|
|
|
|
|
|
|
// have we already used this character in $salt?
|
|
|
|
|
|
|
|
if ( !strstr( $salt, $char ) ){
|
|
|
|
|
|
|
|
// no, so it's OK to add it onto the end of whatever we've already got...
|
|
|
|
|
|
|
|
$salt .= $char;
|
|
|
|
|
|
|
|
// ... and increase the counter by one
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// done!
|
|
|
|
}
|
|
|
|
return $salt;
|
|
|
|
// done!
|
|
|
|
}
|
|
|
|
return $salt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|