forked from pedro3005/whube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
86 lines (76 loc) · 2.14 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* User class stuff, all the user class model stuff.
*
* User class to do CRUD work.
* @author Paul Tagliamonte <paultag@whube.com>
* @version 1.0
* @license: AGPLv3
*/
if ( ! class_exists ( "user" ) ) {
if ( ! class_exists( "dbobj" ) ) {
// last ditch...
$model_root = dirname( __FILE__ ) . "/";
include( $model_root . "dbobj.php" );
}
class user extends dbobj {
function user() {
dbobj::dbobj("users", "uID");
}
function getAllUsers() {
global $TABLE_PREFIX;
$sql = new sql();
$sql->query("SELECT * FROM " . $TABLE_PREFIX . "users;" );
$ret = array();
while ( $row = $sql->getNextRow() ) {
array_push( $ret, $row );
}
return $ret;
}
function validate_email( $email ) {
$isValid = true;
$atIndex = strrpos( $email, "@" );
if ( is_bool( $atIndex ) && !$atIndex ) {
$isValid = false;
} else {
$domain = substr( $email, $atIndex+1 );
$local = substr( $email, 0, $atIndex );
$localLen = strlen( $local );
$domainLen = strlen( $domain );
if( $localLen < 1 || $localLen > 64 ) {
$isValid = false;
} else if( $domainLen < 1 || $domainLen > 255 ) {
$isValid = false;
} else if( $local[0] == '.' || $local[$localLen-1] == '.' ) {
$isValid = false;
} else if( preg_match('/\\.\\./', $local ) ) {
$isValid = false;
} else if( !preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain ) ) {
$isValid = false;
} else if( preg_match('/\\.\\./', $domain ) ) {
$isValid = false;
} else if( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace( "\\\\","",$local ) ) ) {
if ( !preg_match('/^"(\\\\"|[^"])+"$/', str_replace( "\\\\","",$local ) ) ) {
$isValid = false;
}
}
if ($isValid && !( checkdnsrr( $domain,"MX" ) || checkdnsrr( $domain,"A" ) ) ) {
$isValid = false;
}
}
return $isValid;
}
function validate_password( $password, $min, $max ) {
$password = trim( $password );
$bad = eregi_replace( '( [a-zA-Z0-9_]{' . $min_char . ',' . $max_char . '} )', '', $password );
if( empty( $bad ) ) {
$isValid = TRUE;
} else {
$isValid = FALSE;
}
return $isValid;
}
}
}
$USER_OBJECT = new user();
?>