Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Attempts to create account
- // Params: $username = string, username of account to be created (not escaped)
- // $password = string, password of account to be created (not escaped)
- // $email = string, email of account to be created (not escaped)
- // Return: -1 = database error
- // 1 = account craeted
- // 0 = account already exists
- function createAccount($username, $password, $email)
- {
- $mysql_conn = mysql_connect('127.0.0.1', 'website_realmd', 'PASSWORD');
- if (!$mysql_conn)
- return -1;
- if (!mysql_select_db('realmd', $mysql_conn))
- return -1;
- if ($query = mysql_query('SELECT 1 FROM `account` WHERE `username`=\'' . mysql_real_escape_string($username) . '\' LIMIT 1', $mysql_conn))
- {
- if (mysql_num_rows($query))
- return 0;
- }
- mysql_query('INSERT INTO `account` (username, sha_pass_hash, email, expansion) VALUES (\'' . mysql_real_escape_string(strtoupper($username)) . '\',
- \'' . sha1(strtoupper($username . ':' . $password)) . '\', \'' . strtoupper(mysql_real_escape_string($email)) . '\', 2)', $mysql_conn);
- return 1;
- }
Add Comment
Please, Sign In to add comment