Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //--Powered by DarkCoreCMS
- //--Website: http://mmltools.com
- //--Author: Marco aka (Darksoke)
- function connect($ip, $user, $password, $database){
- $con = mysqli_connect($ip, $user, $password, $database) or die('try again in some minutes, please');
- if (!$con)
- printf("Connect failed: %s\n", mysqli_connect_error());
- //exit();
- else
- return $con;
- }
- function encrypt($username, $password)
- {
- $password = sha1(strtoupper($username) . ":" . strtoupper($password));
- $password = strtoupper($password);
- return $password;
- }
- function check_user_exist($username){
- global $db_ip, $db_user, $db_password, $db_auth;
- $con = connect($db_ip, $db_user, $db_password, $db_auth);
- $stmt = $con->prepare("SELECT * FROM account WHERE `username`=?");
- $stmt->bind_param("s", $username);
- $stmt->execute();
- $stmt->store_result();
- return $stmt->num_rows;
- $stmt->close();
- $con->close();
- }
- function clean($string) {
- $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
- return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
- }
- function register_user($username, $password, $repassword, $email){
- if ($password != $repassword){
- echo "<font color='#ff0000;'>Passwords do not match. <br></font>";
- return;
- }
- else
- $new_password = encrypt($username,$password);
- $sql = "INSERT INTO `account` (`username`, `sha_pass_hash`) VALUES (?,?)";
- global $db_ip, $db_user, $db_password, $db_auth;
- $con = connect($db_ip, $db_user, $db_password, $db_auth);
- if (check_user_exist($username) > 0) {
- echo "<font color='#ff0000;'>Username is taken. </font>";
- $con->close();
- return;
- }
- if (check_user_exist($username) == 0) {
- if ($stmt = $con->prepare($sql)) {
- $stmt->bind_param("ss", $username, $new_password);
- $stmt->execute();
- $stmt->close();
- echo "<script type='text/javascript'>window.location.href = '?success=$username';</script>";
- $con->close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement