diff --git a/Website/class.user.php b/Website/class.user.php new file mode 100644 index 0000000..c41e3e8 --- /dev/null +++ b/Website/class.user.php @@ -0,0 +1,94 @@ +dbConnection(); + $this->conn = $db; + } + + public function runQuery($sql) + { + $stmt = $this->conn->prepare($sql); + return $stmt; + } + + public function register($uname,$upass) + { + try + { + //$new_password = password_hash($upass, PASSWORD_DEFAULT); // 3.2.17 ivan changed to cleartext password saving to make it more easy... + $new_password = $upass; + + $stmt = $this->conn->prepare("INSERT INTO users(user_name,user_pass) + VALUES(:uname, :upass)"); + + $stmt->bindparam(":uname", $uname); + $stmt->bindparam(":upass", $new_password); + + $stmt->execute(); + + return $stmt; + } + catch(PDOException $e) + { + echo $e->getMessage(); + } + } + + + public function doLogin($uname,$upass) + { + try + { + $stmt = $this->conn->prepare("SELECT user_id, user_name, user_pass FROM users WHERE user_name=:uname"); + $stmt->execute(array(':uname'=>$uname)); + $userRow=$stmt->fetch(PDO::FETCH_ASSOC); + if($stmt->rowCount() == 1) + { + //if(password_verify($upass, $userRow['user_pass'])) // 3.2.17 ivan changed to cleartext password saving to make it more easy... + if($upass == $userRow['user_pass']) + { + $_SESSION['user_session'] = $userRow['user_id']; + return true; + } + else + { + return false; + } + } + } + catch(PDOException $e) + { + echo $e->getMessage(); + } + } + + public function is_loggedin() + { + if(isset($_SESSION['user_session'])) + { + return true; + } + } + + public function redirect($url) + { + header("Location: $url"); + } + + public function doLogout() + { + session_destroy(); + unset($_SESSION['user_session']); + return true; + } +} +?> diff --git a/Website/dbconfig.php b/Website/dbconfig.php new file mode 100644 index 0000000..bbbf29d --- /dev/null +++ b/Website/dbconfig.php @@ -0,0 +1,27 @@ +conn = null; + try + { + $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); + $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch(PDOException $exception) + { + echo "Connection error: " . $exception->getMessage(); + } + + return $this->conn; + } +} +?> diff --git a/Website/dblogin.sql b/Website/dblogin.sql new file mode 100644 index 0000000..c84be2d --- /dev/null +++ b/Website/dblogin.sql @@ -0,0 +1,39 @@ +-- phpMyAdmin SQL Dump +-- version 4.1.14 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Jan 07, 2016 at 03:05 AM +-- Server version: 5.6.17 +-- PHP Version: 5.5.12 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `dblogin` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE IF NOT EXISTS `users` ( + `user_id` int(11) NOT NULL AUTO_INCREMENT, + `user_name` varchar(15) NOT NULL, + `user_pass` varchar(255) NOT NULL, + `joining_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/Website/home.php b/Website/home.php new file mode 100644 index 0000000..a6cd2a3 --- /dev/null +++ b/Website/home.php @@ -0,0 +1,93 @@ +runQuery("SELECT * FROM users WHERE user_id=:user_id"); + $stmt->execute(array(":user_id"=>$user_id)); + + $userRow=$stmt->fetch(PDO::FETCH_ASSOC); + +?> + + + + + + welcome - <?php print($userRow['user_name']); ?> + + + +
+
+
+
+ +
+

+ + + home +   + + + profile + +

+
+

User Home Page +

+

+ Programming Blog Featuring Tutorials on PHP, MySQL, Ajax, jQuery, Web Design and More... +
+
+ tutorial link + +

+
+
+ + diff --git a/Website/images/logo.png b/Website/images/logo.png new file mode 100644 index 0000000..0d4e92a Binary files /dev/null and b/Website/images/logo.png differ diff --git a/Website/index.html b/Website/index.html deleted file mode 100644 index 2d2a60c..0000000 --- a/Website/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - -
-

Most important heading

-

Less important heading

-
- -
-

The article title

-

Contents of the article element

-
-
-

A new article

-
-

Heading

-

content or image

-
-
- - - diff --git a/Website/index.php b/Website/index.php new file mode 100644 index 0000000..312bec7 --- /dev/null +++ b/Website/index.php @@ -0,0 +1,75 @@ +is_loggedin()!=""){ + $login->redirect('home.php'); +} +if(isset($_POST['btn-login'])){ + $uname = strip_tags($_POST['txt_uname']); + $upass = strip_tags($_POST['txt_password']); + if($login->doLogin($uname,$upass)){ + $login->redirect('home.php'); + } else { + $error = "Wrong Details !"; + } +} +?> + + + + + BusinessStreamline : Login + + + +
+
+ +
+
+ + diff --git a/Website/logout.php b/Website/logout.php new file mode 100644 index 0000000..d78f37e --- /dev/null +++ b/Website/logout.php @@ -0,0 +1,14 @@ +is_loggedin()!="") + { + $user_logout->redirect('home.php'); + } + if(isset($_GET['logout']) && $_GET['logout']=="true") + { + $user_logout->doLogout(); + $user_logout->redirect('index.php'); + } diff --git a/Website/profile.php b/Website/profile.php new file mode 100644 index 0000000..f1ed73c --- /dev/null +++ b/Website/profile.php @@ -0,0 +1,75 @@ +runQuery("SELECT * FROM users WHERE user_id=:user_id"); + $stmt->execute(array(":user_id"=>$user_id)); + + $userRow=$stmt->fetch(PDO::FETCH_ASSOC); + +?> + + + + + + welcome - <?php print($userRow['user_name']); ?> + + + +
+
+
+
+ +
+

+ home   + profile

+
+

Another Secure Profile Page

+

+ Programming Blog Featuring Tutorials on PHP, MySQL, Ajax, jQuery, Web Design and More... +
+
+ tutorial link +

+
+
+ + diff --git a/Website/session.php b/Website/session.php new file mode 100644 index 0000000..680cee8 --- /dev/null +++ b/Website/session.php @@ -0,0 +1,15 @@ +is_loggedin()) + { + // session no set redirects to login page + $session->redirect('index.php'); + } \ No newline at end of file diff --git a/Website/sign-up.php b/Website/sign-up.php new file mode 100644 index 0000000..f410466 --- /dev/null +++ b/Website/sign-up.php @@ -0,0 +1,95 @@ +is_loggedin()!=""){ + $user->redirect('home.php'); +} +if(isset($_POST['btn-signup'])){ + $uname = strip_tags($_POST['txt_uname']); + $upass = strip_tags($_POST['txt_upass']); + if($uname=="") { + $error[] = "provide username !"; + } else if($upass=="") { + $error[] = "provide password !"; + } else if(strlen($upass) < 6){ + $error[] = "Password must be atleast 6 characters"; + } else { + try { + $stmt = $user->runQuery("SELECT user_name FROM users WHERE user_name=:uname"); + $stmt->execute(array(':uname'=>$uname)); + $row=$stmt->fetch(PDO::FETCH_ASSOC); + + if($row['user_name']==$uname) { + $error[] = "sorry username already taken !"; + } else { + if($user->register($uname,$upass)){ + $user->redirect('index.php?joined'); + + } + } + } catch(PDOException $e) { + echo $e->getMessage(); + } + } +} +?> + + + + + Coding Cage : Sign up + + + +
+
+ +
+
+ + diff --git a/Website/style.css b/Website/style.css new file mode 100644 index 0000000..0c3d85b --- /dev/null +++ b/Website/style.css @@ -0,0 +1,67 @@ +@charset "utf-8"; +/* CSS Document */ + +body{ + background:#f1f9f9; +} + +.form-signin { + max-width: 500px; + padding: 19px 29px 29px; + margin: 0 auto; + //margin-top:90px; + background-color: #fff; + + border: 1px solid #e5e5e5; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05); + -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05); + box-shadow: 0 1px 2px rgba(0,0,0,.05); + + font-family:Tahoma, Geneva, sans-serif; + color:#990000; + font-weight:lighter; +} + +.form-signin .form-signin-heading{ + color:#00A2D1; +} +.form-signin .form-signin-line{ + color:#AAA2D1; + font-size: 18px; +} +.form-signin input[type="text"], +.form-signin input[type="password"]{ + font-size: 16px; + height: 45px; + padding: 7px 9px; +} +.btn-big{ + font-size: 16px; + height:45px; + +} +.btn{ + font-size: 14px; + height:45px; + +} +.signin-form, .body-container +{ + //border:solid red 1px; + margin-top:110px; +} +.navbar-brand{ + font-family:"Lucida Handwriting"; +} +#btn-submit{ + height:45px; +} +.h5{ + font-family:Verdana, Geneva, sans-serif; +} +h1{ + font-family:Verdana, Geneva, sans-serif; +}