Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Auth::connect($config);
- class Auth
- {
- public static $config = NULL;
- public static $dbh = NULL;
- public static $stmt = NULL;
- public static $username = NULL;
- public static $password = NULL;
- public static $sessdata = NULL;
- public static $dbuser = NULL;
- public static $dbuser = NULL;
- public static $database = NULL;
- public static $host = NULL;
- public static function configure($config = NULL) {
- self::$dbuser = self::$config["username"];
- self::$dbpass = self::$config["password"];
- self::$database = self::$config["database"];
- self::$host = self::$config["host"];
- }
- public static function connect($config = NULL) {
- if(is_array($config)) {
- self::config($config);
- }
- self::$dbh = new PDO("mysql:host={self::$host};dbname={self::$database}", self::$dbuser, self::$dbpass);
- self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- public static function validateUser() {
- self::$stmt = self::$dbh->prepare("SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1");
- self::$stmt->bindParam(':username', self::$username);
- self::$stmt->bindParam(':password', md5(self::$password));
- self::$stmt->execute();
- return self::$stmt->rowCount() == 1;
- }
- public static function isAuth() {
- if(self::$sessdata["ip"] != $_SERVER['REMOTE_ADDR']) {
- return false;
- }
- self::$stmt = self::$dbh->prepare("SELECT * FROM users WHERE id = :id AND password = :password LIMIT 1");
- self::$stmt->bindParam(':id', self::$sessdata["id"]);
- self::$stmt->bindParam(':password', self::$sessdata["salty"]);
- self::$stmt->execute();
- return self::$stmt->rowCount() == 1;
- }
- public static function generateSess() {
- $result = self::$stmt->fetch();
- return array("id" => $result["id"], "ip" => $_SERVER["REMOTE_ADDR"], "salty" => $result["password"]);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment