Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBConnector
- {
- private $databaseConnection;
- function dbConnect()
- {
- try
- {
- $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
- }
- catch(PDOException $e) {
- echo 'ERROR: ' . $e->getMessage();
- }
- }
- function checkUserPassword($username,$password)
- {
- try
- {
- $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
- }
- catch(PDOException $e) {
- return false;
- }
- //get username record from db
- $records = $this->databaseConnection->prepare('SELECT usr_username,usr_password FROM users WHERE usr_username = :username');
- $records->bindParam(':username', $username ,PDO::PARAM_STR);
- $records->execute();
- $results = $records->fetch(PDO::FETCH_NUM);
- if(!$results)
- {
- return false;
- }
- else
- {
- $saltedPassword = $GLOBALS["CONFIGURATION"]["dbsalt1"] . $password . $GLOBALS["CONFIGURATION"]["dbsalt2"];
- $token = hash('ripemd128',"$saltedPassword");
- if ($results[1]==$token)
- return true;
- else
- return false;
- }
- }
- function changePassword($oldPassword)
- {
- try
- {
- $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
- // set the PDO error mode to exception
- $this->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- $sql = "UPDATE agis_moulds SET usr_password='Doe' WHERE usr_password = :password";
- // Prepare statement
- $records = $this->prepare($sql);
- // execute the query
- $records->execute();
- }
- catch ( PDOException $e )
- {
- echo $sql . "<br>" . $e->getMessage ();
- }
- $this->databaseConnection = null;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement