Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This class is used to manage user login/checking
- * It pulls config details from config.txt
- **/
- class userManagement{
- /**
- * Used to assign the information to the variables
- **/
- function __construct(){
- $this->db_host = parseConfig("db_host");
- $this->db_user = parseConfig("db_user");
- $this->db_pass = parseConfig("db_pass");
- $this->db_db = parseConfig("db_db");
- $this->db_prefix = parseConfig("db_prefix");
- }
- /**
- * This is used to connect to the database, so further
- * operations can be carried out further on in the
- * class.
- **/
- private function mysqlConnect(){
- $this->mysqlCon = mysqli_connect($this->db_host,$this->db_user,$this->db_pass,$this->db_db);
- if(!$this->mysqlCon){
- return "ERROR: Could not connect";
- }
- }
- /**
- * Disconnects from the database
- **/
- private function mysqlKill(){
- if($this->mysqlCon){
- mysqli_close($this->mysqlCon);
- return TRUE;
- }else{
- return FALSE;
- }
- }
- /**
- * This take 2 params: username and password,
- * it then checks them against the database.
- * This function salts the hash, concatenating
- * username and password, to form a relitavely
- * strong hash.
- **/
- public function userAuth($username,$password){
- $this->mysqlConnect();
- $saltedPass = sha1($username.$password);
- $mysqlData = mysqli_query($this->mysqlCon,"SELECT username, password, uid FROM ".$this->db_prefix."users WHERE username = '".$username."' AND password = '".$saltedPass."'");
- if(!$mysqlData){
- session_unset();
- $_SESSION["userAuthed"] = FALSE;
- return FALSE;
- }
- if(mysqli_num_rows($mysqlData) == 1){
- $usersTable = mysqli_fetch_array($mysqlData);
- $_SESSION["userAuthed"] = TRUE;
- $_SESSION["username"] = $username;
- $_SESSION["uid"] = $row["uid"];
- return TRUE;
- }
- $this->mysqlKill();
- }
- /**
- * The following function is used when a user
- * registers on the site, and inputs their
- * data into the users, and userinfo tables.
- **/
- public function userRegister($username, $password, $email, $name){
- $this->mysqlConnect();
- $saltedPass = sha1($username.$password);
- if(!mysqli_query($this->mysqlCon,"INSERT INTO ".$this->db_prefix."users (username,password,email,name) VALUES ($username,$password,$email,$name)")){
- return FALSE;
- }else{
- $message = "Thank you $name for registering to the ".parseConfig("title")." $name. I hope this works.";
- mail($email,"Thank you for registering!",$message);
- return TRUE;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement