Project

General

Profile

« Previous | Next » 

Revision 1446

Added by DarkViper over 13 years ago

fixed validation of loginname (admin/users and signup)

View differences:

branches/2.8.x/wb/admin/users/save.php
56 56
if($groups_id == "") {
57 57
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
58 58
}
59
if(strlen($username) < 2) {
60
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
59
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
60
	$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
61
	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
61 62
}
62 63
if($password != "") {
63 64
	if(strlen($password) < 2) {
......
114 115

  
115 116
// Print admin footer
116 117
$admin->print_footer();
117

  
118
?>
branches/2.8.x/wb/admin/users/add.php
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Print admin header
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Access', 'users_add');
23

  
24
// Create a javascript back link
25
$js_back = ADMIN_URL.'/users/index.php';
26

  
27
// Create new database object
28
//$database = new database();
29
if( !$admin->checkFTAN() )
30
{
31
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back);
32
	exit();
33
}
34

  
35
// Get details entered
36
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : ''; //should check permissions
37
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
38
$active = $admin->add_slashes($_POST['active'][0]);
39
$username_fieldname = $admin->get_post_escaped('username_fieldname');
40
$username = strtolower($admin->get_post_escaped($username_fieldname));
41
$password = $admin->get_post('password');
42
$password2 = $admin->get_post('password2');
43
$display_name = $admin->get_post_escaped('display_name');
44
$email = $admin->get_post_escaped('email');
45
$home_folder = $admin->get_post_escaped('home_folder');
46
$default_language = DEFAULT_LANGUAGE;
47

  
48
// Check values
49
if($groups_id == '') {
50
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
51
}
52
if(strlen($username) < 2) {
53
	$admin->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back);
54
}
55
if(strlen($password) < 2) {
56
	$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
57
}
58
if($password != $password2) {
59
	$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
60
}
61
if($email != '')
62
{
63
	if($admin->validate_email($email) == false)
64
    {
65
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
66
	}
67
} else { // e-mail must be present
68
	$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
69
}
70

  
71
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
72
$gid_tmp = explode(',', $groups_id);
73
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group
74
else $group_id = $gid_tmp[0]; // else just get the first one
75
unset($gid_tmp);
76

  
77
// Check if username already exists
78
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
79
if($results->numRows() > 0) {
80
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
81
}
82

  
83
// Check if the email already exists
84
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
85
if($results->numRows() > 0)
86
{
87
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
88
    {
89
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
90
	} else {
91
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
92
	}
93
}
94

  
95
// MD5 supplied password
96
$md5_password = md5($password);
97

  
98
// Inser the user into the database
99
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$group_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')";
100
$database->query($query);
101
if($database->is_error()) {
102
	$admin->print_error($database->get_error());
103
} else {
104
	$admin->print_success($MESSAGE['USERS']['ADDED']);
105
}
106

  
107
// Print admin footer
108
$admin->print_footer();
109

  
110
?>
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         users
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Print admin header
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Access', 'users_add');
23

  
24
// Create a javascript back link
25
$js_back = ADMIN_URL.'/users/index.php';
26

  
27
// Create new database object
28
//$database = new database();
29
if( !$admin->checkFTAN() )
30
{
31
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back);
32
	exit();
33
}
34

  
35
// Get details entered
36
$groups_id = (isset($_POST['groups'])) ? implode(",", $admin->add_slashes($_POST['groups'])) : ''; //should check permissions
37
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
38
$active = $admin->add_slashes($_POST['active'][0]);
39
$username_fieldname = $admin->get_post_escaped('username_fieldname');
40
$username = strtolower($admin->get_post_escaped($username_fieldname));
41
$password = $admin->get_post('password');
42
$password2 = $admin->get_post('password2');
43
$display_name = $admin->get_post_escaped('display_name');
44
$email = $admin->get_post_escaped('email');
45
$home_folder = $admin->get_post_escaped('home_folder');
46
$default_language = DEFAULT_LANGUAGE;
47

  
48
// Check values
49
if($groups_id == '') {
50
	$admin->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back);
51
}
52
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
53
	$admin->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
54
	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
55
}
56
if(strlen($password) < 2) {
57
	$admin->print_error($MESSAGE['USERS']['PASSWORD_TOO_SHORT'], $js_back);
58
}
59
if($password != $password2) {
60
	$admin->print_error($MESSAGE['USERS']['PASSWORD_MISMATCH'], $js_back);
61
}
62
if($email != '')
63
{
64
	if($admin->validate_email($email) == false)
65
    {
66
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
67
	}
68
} else { // e-mail must be present
69
	$admin->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back);
70
}
71

  
72
// choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
73
$gid_tmp = explode(',', $groups_id);
74
if(in_array('1', $gid_tmp)) $group_id = '1'; // if user is in administrator-group, get this group
75
else $group_id = $gid_tmp[0]; // else just get the first one
76
unset($gid_tmp);
77

  
78
// Check if username already exists
79
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
80
if($results->numRows() > 0) {
81
	$admin->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back);
82
}
83

  
84
// Check if the email already exists
85
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$admin->add_slashes($_POST['email'])."'");
86
if($results->numRows() > 0)
87
{
88
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN']))
89
    {
90
		$admin->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back);
91
	} else {
92
		$admin->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back);
93
	}
94
}
95

  
96
// MD5 supplied password
97
$md5_password = md5($password);
98

  
99
// Inser the user into the database
100
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,home_folder,email,timezone, language) VALUES ('$group_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$home_folder','$email','-72000', '$default_language')";
101
$database->query($query);
102
if($database->is_error()) {
103
	$admin->print_error($database->get_error());
104
} else {
105
	$admin->print_success($MESSAGE['USERS']['ADDED']);
106
}
107

  
108
// Print admin footer
109
$admin->print_footer();
110

  
111
?>
branches/2.8.x/wb/account/signup2.php
1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Must include code to stop this file being access directly
20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
21

  
22
require_once(WB_PATH.'/framework/class.wb.php');
23
$wb = new wb('Start', 'start', false, false);
24

  
25
// Create new database object
26
// $database = new database();
27

  
28
// Get details entered
29
$groups_id = FRONTEND_SIGNUP;
30
$active = 1;
31
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
32
$display_name = strip_tags($wb->get_post_escaped('display_name'));
33
$email = $wb->get_post('email');
34

  
35
// Create a javascript back link
36
$js_back = WB_URL.'/account/signup.php';
37

  
38
if (!$wb->checkFTAN())
39
{
40
	$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back, false);
41
	exit();
42
}
43

  
44
// Check values
45
if($groups_id == "") {
46
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
47
}
48
if(strlen($username) < 3) {
49
	$wb->print_error($MESSAGE['USERS']['USERNAME_TOO_SHORT'], $js_back, false);
50
}
51
if($email != "") {
52
	if($wb->validate_email($email) == false) {
53
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
54
	}
55
} else {
56
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
57
}
58

  
59
$email = $wb->add_slashes($email);
60

  
61
// Captcha
62
if(ENABLED_CAPTCHA) {
63
	if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
64
		// Check for a mismatch
65
		if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
66
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
67
		}
68
	} else {
69
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
70
	}
71
}
72
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
73

  
74
// Generate a random password then update the database with it
75
$new_pass = '';
76
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
77
srand((double)microtime()*1000000);
78
$i = 0;
79
while ($i <= 7) {
80
	$num = rand() % 33;
81
	$tmp = substr($salt, $num, 1);
82
	$new_pass = $new_pass . $tmp;
83
	$i++;
84
}
85
$md5_password = md5($new_pass);
86

  
87
// Check if username already exists
88
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
89
if($results->numRows() > 0) {
90
	$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
91
}
92

  
93
// Check if the email already exists
94
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'");
95
if($results->numRows() > 0) {
96
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
97
		$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
98
	} else {
99
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
100
	}
101
}
102

  
103
// MD5 supplied password
104
$md5_password = md5($new_pass);
105

  
106
// Inser the user into the database
107
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,email) VALUES ('$groups_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$email')";
108
$database->query($query);
109

  
110
if($database->is_error()) {
111
	// Error updating database
112
	$message = $database->get_error();
113
} else {
114
	// Setup email to send
115
	$mail_to = $email;
116
	$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
117

  
118
	// Replace placeholders from language variable with values
119
	$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
120
	$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass); 
121
	$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
122

  
123
	// Try sending the email
124
	if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { 
125
		$display_form = false;
126
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php' );
127
	} else {
128
		$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
129
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
130
	}
131
}
132

  
133
?>
1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Must include code to stop this file being access directly
20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
21

  
22
require_once(WB_PATH.'/framework/class.wb.php');
23
$wb = new wb('Start', 'start', false, false);
24

  
25
// Create new database object
26
// $database = new database();
27

  
28
// Get details entered
29
$groups_id = FRONTEND_SIGNUP;
30
$active = 1;
31
$username = strtolower(strip_tags($wb->get_post_escaped('username')));
32
$display_name = strip_tags($wb->get_post_escaped('display_name'));
33
$email = $wb->get_post('email');
34

  
35
// Create a javascript back link
36
$js_back = WB_URL.'/account/signup.php';
37

  
38
if (!$wb->checkFTAN())
39
{
40
	$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back, false);
41
	exit();
42
}
43

  
44
// Check values
45
if($groups_id == "") {
46
	$wb->print_error($MESSAGE['USERS']['NO_GROUP'], $js_back, false);
47
}
48
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
49
	$wb->print_error( $MESSAGE['USERS_NAME_INVALID_CHARS'].' / '.
50
	                  $MESSAGE['USERS_USERNAME_TOO_SHORT'], $js_back);
51
}
52
if($email != "") {
53
	if($wb->validate_email($email) == false) {
54
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
55
	}
56
} else {
57
	$wb->print_error($MESSAGE['SIGNUP']['NO_EMAIL'], $js_back, false);
58
}
59

  
60
$email = $wb->add_slashes($email);
61

  
62
// Captcha
63
if(ENABLED_CAPTCHA) {
64
	if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
65
		// Check for a mismatch
66
		if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
67
			$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
68
		}
69
	} else {
70
		$wb->print_error($MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'], $js_back, false);
71
	}
72
}
73
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
74

  
75
// Generate a random password then update the database with it
76
$new_pass = '';
77
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
78
srand((double)microtime()*1000000);
79
$i = 0;
80
while ($i <= 7) {
81
	$num = rand() % 33;
82
	$tmp = substr($salt, $num, 1);
83
	$new_pass = $new_pass . $tmp;
84
	$i++;
85
}
86
$md5_password = md5($new_pass);
87

  
88
// Check if username already exists
89
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE username = '$username'");
90
if($results->numRows() > 0) {
91
	$wb->print_error($MESSAGE['USERS']['USERNAME_TAKEN'], $js_back, false);
92
}
93

  
94
// Check if the email already exists
95
$results = $database->query("SELECT user_id FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($email)."'");
96
if($results->numRows() > 0) {
97
	if(isset($MESSAGE['USERS']['EMAIL_TAKEN'])) {
98
		$wb->print_error($MESSAGE['USERS']['EMAIL_TAKEN'], $js_back, false);
99
	} else {
100
		$wb->print_error($MESSAGE['USERS']['INVALID_EMAIL'], $js_back, false);
101
	}
102
}
103

  
104
// MD5 supplied password
105
$md5_password = md5($new_pass);
106

  
107
// Inser the user into the database
108
$query = "INSERT INTO ".TABLE_PREFIX."users (group_id,groups_id,active,username,password,display_name,email) VALUES ('$groups_id', '$groups_id', '$active', '$username','$md5_password','$display_name','$email')";
109
$database->query($query);
110

  
111
if($database->is_error()) {
112
	// Error updating database
113
	$message = $database->get_error();
114
} else {
115
	// Setup email to send
116
	$mail_to = $email;
117
	$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
118

  
119
	// Replace placeholders from language variable with values
120
	$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
121
	$replace = array($display_name, WEBSITE_TITLE, $username, $new_pass); 
122
	$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
123

  
124
	// Try sending the email
125
	if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { 
126
		$display_form = false;
127
		$wb->print_success($MESSAGE['FORGOT_PASS']['PASSWORD_RESET'], WB_URL.'/account/login.php' );
128
	} else {
129
		$database->query("DELETE FROM ".TABLE_PREFIX."users WHERE username = '$username'");
130
		$wb->print_error($MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'], $js_back, false);
131
	}
132
}
133

  
134
?>

Also available in: Unified diff