Understanding how user usernames and passwords are saved, retrieved and verified on websites

Environment: Lets consider you have a web site that is developed in PHP with MySQL DB in the backend and pages being served via the Apache Web Server.  All are freeware technologies with appropriate licensing terms.   End User input to Webpage and Webpage to Php script: A user login and/or registration page will prompt user for providing the username and password to access the site content.  The Login page form, will pass the user provided username and password to the appropriate php script.   Php Script to/from DB and back to Web page form: The php script will make […]

Read more

Connecting to your MySQL Database from a Php page using PDO (PHP Data Objects)

  In order to connect to a MySQL DB from Php, you need to frame the connection string and   Index.php <?php     include_once("config.php"); ?>   Config.php <?php     //set off all error for security purposes     error_reporting(E_ALL);         //define some contstant     define( "DB_DSN", "mysql:host=localhost;dbname=<myDBName>" );     define( "DB_USERNAME", "root" );     define( "DB_PASSWORD", "<myrootpasswordhere>" );     define( "CLS_PATH", "class" );     //include the classes     include_once( CLS_PATH . "/DBClass.php" ); ?>   DBClass.php <?php class DBClass {     public function Connect_mysqlDB(){         try {             $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );             $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION […]

Read more

Creating new Database and a new table in MySQL via PhpMyAdmin

Login to your PhpMyAdmin page,   Syntax: SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; CREATE DATABASE `DialogDB` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `<MyDBName>`; CREATE TABLE IF NOT EXISTS `<MyTableName>` (   `userID` int(11) NOT NULL AUTO_INCREMENT,   `username` varchar(50) NOT NULL,   `password` varbinary(250) NOT NULL,   PRIMARY KEY (`userID`,`username`) ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;   Example:   Output: SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";# MySQL returned an empty result set (i.e. zero rows). SET time_zone = "+00:00";# MySQL returned an empty result set (i.e. zero rows). CREATE DATABASE `DialogDB` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;# 1 row affected. USE `DialogDB`;# MySQL […]

Read more