1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- require_once(realpath(dirname(__FILE__)).'/config.php');
- require_once(PATH_PHP.'database.php');
- require_once(PATH_PHP.'security.php');
- function addUser($username,$password,$email){
- $salt = get_sql()->escape_string(salt());
- $email = get_sql()->escape_string($email);
- $username = get_sql()->escape_string($username);
- $hash = get_sql()->escape_string(saltedHash($password,$salt));
- $res = query("INSERT INTO `users` (email,name,password,salt) VALUES ('%s','%s','%s','%s')",Array($email,$username,$hash,$salt));
- alog('u',mysqli_insert_id(get_sql()),'User Created');
- return $res;
- }
- function isUser($name){
- $res = query("SELECT id FROM `users` WHERE name='%s'",Array($name));
- if($res->num_rows == 1){
- return true;
- }else{
- return false;
- }
- }
- function userId($name){
- if($user = query("SELECT id FROM `users` WHERE name='%s'",Array($name))){
- if($user->num_rows == 1){
- $user = $user->fetch_assoc();
- return $user['id'];
- }
- }
- return false;
- }
- function userObj($id){
- if(is_string($id)){
- $id = userId($id);
- }
- if($res = query("SELECT * FROM `users` WHERE id='%d'",Array($id))){
- if($res->num_rows == 1){
- if($user = $res->fetch_assoc()){
- unset($user['password']);
- unset($user['salt']);
- unset($user['key']);
- return $user;
- }
- }
- }
- return false;
- }
- ?>
|