forked from blamarche/openbookmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
164 lines (148 loc) · 4.71 KB
/
register.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
require_once ("./header.php");
$secret = "dDWUc72sCcs20cXskcw";
$reg_register = set_post_bool_var ('reg_register', false);
$reg_username = set_post_string_var ('reg_username');
$reg_email = set_post_string_var ('reg_email');
$confirm = set_get_string_var ('confirm');
if ($reg_register) {
if ($reg_username != "") {
if (check_username ($reg_username)) {
echo '<div style="color:red;">$username is an already registered user. Choose another one.</div>'."\n";
$username = false;
}
else {
$username = $reg_username;
}
}
else {
echo '<div style="color:red;">Please enter a Username.</div>'."\n";
$username = false;
}
if (isset ($_POST['reg_password1']) && $_POST['reg_password1'] != "" &&
isset ($_POST['reg_password2']) && $_POST['reg_password2'] != "") {
if (md5 ($_POST['reg_password1']) != md5 ($_POST['reg_password2'])) {
echo '<div style="color:red;">Passwords do not match.</div>'."\n";
$password = false;
}
else {
$password = md5 ($_POST['reg_password1']);
}
}
else {
echo '<div style="color:red;">Please fill out both password fields.</div>'."\n";
$password = false;
}
if ($reg_email != '') {
if (preg_match ('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $reg_email)) {
$query = "SELECT COUNT(*) AS result FROM user WHERE email='$reg_email'";
if ($mysql->query ($query)) {
if (mysql_result ($result, 0) > 0) {
echo '<div style="color:red;">A User Account with this email address aready exists.</div>'."\n";
$email = false;
}
else {
$email = $reg_email;
}
}
else {
$email = false;
message ($mysql->error);
}
}
else {
echo '<div style="color:red;">Email address is invalid.</div>'."\n";
$email = false;
}
}
else {
echo '<div style="color:red;">Please enter a valid email address.</div>'."\n";
$email = false;
}
if ($username && $password && $email) {
$query = " INSERT INTO user
(username, password, email, active)
VALUES
('$username', md5('$password'), '$email', '0')";
if (mysql_query ("$query")) {
# dieser key wird als username und secret md5 hash an den
# user geschickt und für die verifikation der registrierung gebraucht.
$key = md5 ($username . $secret);
$headers = "From: noreply@yourdomain.com\r\n" .
$subject = 'Your registration at yourdomain.com';
$message = "Hi $username,\r\n\r\n";
$message .= "This email confirms the creation of your OpenBookmark user account. ";
$message .= "Your username is '$username'. For security reasons your password is not ";
$message .= "included in this email. To activate your account, visit the following URL:\r\n\r\n";
$message .= "http://www.yourdomain.com/register.php?confirm=$key\r\n\r\n";
$message .= "In case of complications regarding this user account registration, ";
$message .= "please contact support@yourdomain.com\r\n\r\n";
$message .= "With kind regards, your yourdomain.com Team";
mail($email, $subject, $message, $headers);
echo " you have been successfully registered.
Read your email and click the link to activate your account.";
}
else {
echo mysql_error ();
}
}
else {
display_register_form ();
}
}
else if ($confirm != '' && strlen ($confirm) === 32) {
$query = "SELECT username FROM user WHERE MD5(CONCAT(username,'$secret'))='$confirm' AND active='0'";
$result = mysql_query ("$query");
if (mysql_num_rows ($result) == 1) {
# the registration confirmation was successufull,
# thus we can enable the useraccount in the database.
$username = mysql_result ($result, 0);
$query = "UPDATE user SET active='1' WHERE username='$username' AND active='0'";
if (mysql_query ($query)) {
echo "You are now registered. Happy bookmarking!";
}
}
else {
display_register_form ();
}
}
else {
display_register_additional_text ();
display_register_form ();
}
function display_register_form () {
?>
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>" name="loginform">
<table border="0">
<tr>
<td>Username:</td>
<td><input name="reg_username" type="text" value=""></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="reg_password1" type="password" value=""></td>
</tr>
<tr>
<td>Password Verification:</td>
<td><input name="reg_password2" type="password" value=""></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input name="reg_email" type="text" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register" name="reg_register"></td>
</tr>
</table>
</form>
<?php
}
function display_register_additional_text () {
?>
<p>Please provide the information bellow to register.</p>
<p>If you are already a registered user, <a class="orange" href="./index.php">you can log in here.</a></p>
<?php
}
require_once ("./footer.php");
?>