Back to the module list

Authentication SQL

Authenticate the user on a SQL database.

The SQL database use the PDO abstraction layer, si it can be MySQL, PostgreSQL, or SQLite.

The password must be encrypted in the database.

The module allow to change the password.

The class definition

Class \authsql

Namespace \


 User authentication against SQL database


public $appName;
 The application name
public $driver_options;
 The driver options for the PDO driver
public $dsn;
 The DSN to use to connect to SQL database
public $fieldFirstname;
 The field name containing the Firstname of the user
public $fieldIdentifier="email";
 The identifier field name (maybe email)
public $fieldLastname;
 The field name containing the lastname of the user
public $fieldPassword="password";
 The password field name
public $fieldsInfo=array ();
 The information fields (in an array)
public $password;
 The password to use to connecto to the database
public $table;
 The table name to use
public $tableprefix="";
 The tableprefix text to prepend to table name (Should finish by _)
      Just allow chars !
public $username;
 The username to connect to the database


public function authentication ($email, $password)
 Try to authenticate the email/password of the user
      @param string $email Email to authenticate
      @param string $password Password to authenticate

public function changepassword ($oldpassword, $newpassword)
 Method to change the password
      @param string $oldpassword The old password (to check if the user have the
         rights to change the password)
      @param string $newpassword The new password to be recorded

public function connect ()
 Establish a connection to a SQL server

public function getdetails ()
 Return all the parameters recorded for the authenticate user

public function listusers ()
 List all the users available in the database
      Return firstname, lastname, mail, with mail is an array

public function logout ()
 Method to disconnect the authenticated user

public function overwritepassword ($email, $newpassword)
 Method to overwrite the password (without oldpassword check)
      Must be reserved to the administrators. For the users, use changepassword
      @param string $email the user identifier to select
      @param string $newpassword The new password to be recorded

public function pageHTML ($baseURL, $message="", $url="", $alreadyAuth=false)
 Display the authentication page
 The message is displayed to the user in case of error
 The url is the caller url to go back if authentication is correct
 @param string $baseURL The URL base to use for the links
 @param string|null $message Message to display to the user
 @param string|null $url URL to go back after successful authentication
 @param mixed $alreadyAuth If the user is already authenticated, the value
 will be displayed if the user is coming on the page.