Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function Error($Error)
- {
- echo "<center><b><span style='color:#FFFFFF;'>" . $Error . "</span></b></center>";
- }
- function ConnectMysql()
- {
- include('functions/configs.php');
- $link=mysql_connect("" . $mysql_host . "","" . $mysql_user . "","" . $mysql_pass . "");
- if(!$link) {
- echo "Cannot connect to database!";
- }else{
- mysql_select_db("". $mysql_db . "",$link);
- }
- }
- function register()
- {
- include('functions/configs.php');
- if($core == 1) {
- $flags = 2;
- ConnectMysql();
- $user_chars = "#[^a-zA-Z0-9_\-]#";
- if ((empty($_POST["user"]))||(empty($_POST["password"])) ) {
- echo "<script type='text/javascript'>window.alert('You have not filled in username/password!')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- }
- } else {
- $username = strtoupper($_POST["user"]);
- $password = strtoupper($_POST["password"]);
- if (strlen($username) < 3) {
- echo "<script type='text/javascript'>window.alert('Entered username is too short.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if (strlen($username) > 25) {
- echo "<script type='text/javascript'>window.alert('Entered username is too long.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if (strlen($password) < 3) {
- echo "<script type='text/javascript'>window.alert('Entered password is too short.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if (strlen($password) > 25) {
- echo "<script type='text/javascript'>window.alert('Entered password is too long.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if (preg_match($user_chars,$username)) {
- echo "<script type='text/javascript'>window.alert('Entered username contains illegal characters.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if (preg_match($user_chars,$password)) {
- echo "<script type='text/javascript'>window.alert('Entered password contains illegal characters.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- $username = mysql_real_escape_string($username);
- $password = mysql_real_escape_string($password);
- $qry = mysql_query("SELECT username FROM account WHERE username = '" . $username . "'");
- if (!$qry) {
- echo "<script type='text/javascript'>window.alert('Error querying database, try again later.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- if ($existing_username = mysql_fetch_assoc($qry)) {
- foreach ($existing_username as $key => $value) {
- $existing_username = $value;
- };
- };
- $existing_username = strtoupper($existing_username);
- if ($existing_username == strtoupper($_POST['user'])) {
- echo "<script type='text/javascript'>window.alert('Sorry, that username is already taken.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- unset($qry);
- $sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
- $register_sql = "INSERT INTO account (username, sha_pass_hash, expansion) VALUES ('" . $username . "','" . $sha_pass_hash . "','" . $flags . "')";
- $qry = mysql_query($register_sql);
- if (!$qry) {
- echo "<script type='text/javascript'>window.alert('Error creating account.')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- exit();
- };
- echo "<script type='text/javascript'>window.alert('Account successfully created!')</script><meta http-equiv=\"refresh\" content=\"0;URL=register.php\" />";
- };
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement