Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Requests
User login
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="GarettM" data-source="post: 406101" data-attributes="member: 839"><p>Quick question do we need to create the user/account table or do you have on i need to use?</p><p></p><p>Well here is the database table.</p><p>[CODE]</p><p>CREATE TABLE `accounts` (</p><p> `id` INT(12) NOT NULL AUTO_INCREMENT,</p><p> `username` VARCHAR(64) NOT NULL,</p><p> `email` VARCHAR(64) NOT NULL,</p><p> `hash` VARCHAR(64) NOT NULL,</p><p> `session_id` INT(12) NOT NULL DEFAULT '0',</p><p> `last_online` DATETIME,</p><p> `online` BOOL NOT NULL DEFAULT true,</p><p> PRIMARY KEY(`id`)</p><p>) COLLATE='utf8_general_ci';</p><p>[/CODE]</p><p></p><p>And here is the PHP</p><p>[PHP]</p><p><div class="container"></p><p> <?php</p><p> /**</p><p> * Use This code to generate user hash's</p><p> * $password = (string)filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> * $hash = password_hash($password, PASSWORD_BCRYPT);</p><p> * $statement = $database->prepare('INSERT INTO accounts (username, password, email, session, online) VALUES (:username, :password, :email, :session, :online)');</p><p> * $statement->bindValues(':password', $hash);</p><p> * $statement->execute();</p><p> */</p><p> </p><p> /**</p><p> * Initialize the session</p><p> */</p><p> if(!session_id())</p><p> session_start();</p><p></p><p> /**</p><p> * Database Connection - SQL i used to test (password is password): INSERT INTO `accounts` (`username`, `email`, `hash`, `last_online`) values ('GarettM', 'mrgarett@gmail.com', '$2y$10$oPZ6oIvwomEjaVnq9p6vOuK6yu1k/sEERUw33lf9wZsZ.0zQic4qG', NOW());</p><p> */</p><p> try {</p><p> $database = new PDO('mysql:dbname=anneyemegi;host=localhost', 'root', '', array(</p><p> PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",</p><p> PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,</p><p> PDO::ATTR_EMULATE_PREPARES => FALSE</p><p> ));</p><p> } catch(PDOException $ex) {</p><p> # Handle Exception with $ex</p><p> echo ($ex->getMessage());</p><p> }</p><p> </p><p> /**</p><p> * Check if login was submitted</p><p> */</p><p> if(isset($_POST, $_POST['username'], $_POST['password']))</p><p> {</p><p> $username = (string)filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);</p><p> $password = (string)filter_input(INPUT_POST, 'password', FILTER_SANITIZE_FULL_SPECIAL_CHARS);</p><p> </p><p> $query = 'SELECT * FROM accounts WHERE ( username = :username OR email = :email )';</p><p> $statement = $database->prepare($query);</p><p> $statement->bindValue(':username', $username);</p><p> $statement->bindValue(':email', $username);</p><p> $statement->execute();</p><p> </p><p> $account = $statement->fetch(PDO::FETCH_ASSOC);</p><p> </p><p> if(password_verify($password, $account['hash']))</p><p> {</p><p> $_SESSION['account'] = array();</p><p> foreach($account as $key => $value)</p><p> {</p><p> $_SESSION['account'][$key] = $value;</p><p> }</p><p> </p><p> $query = 'UPDATE accounts SET session_id = :session_id, last_online = NOW(), online = true';</p><p> $update_statement = $database->prepare($query);</p><p> $update_statement->bindValue(':session_id', (string)session_id());</p><p> $update_statement->execute();</p><p> </p><p> # SUCCESS - If you wanna redirect on successfull login uncomment line below.</p><p> #header('Location: /account');</p><p> echo 'Logged in';</p><p> }</p><p> else {</p><p> $error = 'Invalid Credentials';</p><p> }</p><p> }</p><p> ?></p><p> </p><p> <?php</p><p> global $error;</p><p> if(isset($error[1]))</p><p> {</p><p> echo $error;</p><p> }</p><p> ?></p><p> <form class="form-signin form-group"action="" method="post"></p><p> <h2 class="form-signin-heading">Lütfen Giriş Yapın</h2></p><p> <label for="inputEmail" class="sr-only">Email address</label></p><p> <input type="text" id="ad" class="form-control" placeholder="Kullanıcı Adı" autofocus name="username"> <br></p><p> <label for="inputPassword" class="sr-only" name="sifre">Şifre</label></p><p> <input type="password" id="sifre" class="form-control" placeholder="Şifre" name="password"></p><p></p><p> <button class="btn btn-lg btn-primary btn-block" type="submit">Giriş</button></p><p> </form></p><p></p><p> </div><?php } ?> <!-- /container --></p><p></html></p><p>[/PHP]</p><p>[doublepost=1491433997,1491429608][/doublepost]DONE BITCHES</p></blockquote><p></p>
[QUOTE="GarettM, post: 406101, member: 839"] Quick question do we need to create the user/account table or do you have on i need to use? Well here is the database table. [CODE] CREATE TABLE `accounts` ( `id` INT(12) NOT NULL AUTO_INCREMENT, `username` VARCHAR(64) NOT NULL, `email` VARCHAR(64) NOT NULL, `hash` VARCHAR(64) NOT NULL, `session_id` INT(12) NOT NULL DEFAULT '0', `last_online` DATETIME, `online` BOOL NOT NULL DEFAULT true, PRIMARY KEY(`id`) ) COLLATE='utf8_general_ci'; [/CODE] And here is the PHP [PHP] <div class="container"> <?php /** * Use This code to generate user hash's * $password = (string)filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS); * $hash = password_hash($password, PASSWORD_BCRYPT); * $statement = $database->prepare('INSERT INTO accounts (username, password, email, session, online) VALUES (:username, :password, :email, :session, :online)'); * $statement->bindValues(':password', $hash); * $statement->execute(); */ /** * Initialize the session */ if(!session_id()) session_start(); /** * Database Connection - SQL i used to test (password is password): INSERT INTO `accounts` (`username`, `email`, `hash`, `last_online`) values ('GarettM', 'mrgarett@gmail.com', '$2y$10$oPZ6oIvwomEjaVnq9p6vOuK6yu1k/sEERUw33lf9wZsZ.0zQic4qG', NOW()); */ try { $database = new PDO('mysql:dbname=anneyemegi;host=localhost', 'root', '', array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => FALSE )); } catch(PDOException $ex) { # Handle Exception with $ex echo ($ex->getMessage()); } /** * Check if login was submitted */ if(isset($_POST, $_POST['username'], $_POST['password'])) { $username = (string)filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS); $password = (string)filter_input(INPUT_POST, 'password', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $query = 'SELECT * FROM accounts WHERE ( username = :username OR email = :email )'; $statement = $database->prepare($query); $statement->bindValue(':username', $username); $statement->bindValue(':email', $username); $statement->execute(); $account = $statement->fetch(PDO::FETCH_ASSOC); if(password_verify($password, $account['hash'])) { $_SESSION['account'] = array(); foreach($account as $key => $value) { $_SESSION['account'][$key] = $value; } $query = 'UPDATE accounts SET session_id = :session_id, last_online = NOW(), online = true'; $update_statement = $database->prepare($query); $update_statement->bindValue(':session_id', (string)session_id()); $update_statement->execute(); # SUCCESS - If you wanna redirect on successfull login uncomment line below. #header('Location: /account'); echo 'Logged in'; } else { $error = 'Invalid Credentials'; } } ?> <?php global $error; if(isset($error[1])) { echo $error; } ?> <form class="form-signin form-group"action="" method="post"> <h2 class="form-signin-heading">Lütfen Giriş Yapın</h2> <label for="inputEmail" class="sr-only">Email address</label> <input type="text" id="ad" class="form-control" placeholder="Kullanıcı Adı" autofocus name="username"> <br> <label for="inputPassword" class="sr-only" name="sifre">Şifre</label> <input type="password" id="sifre" class="form-control" placeholder="Şifre" name="password"> <button class="btn btn-lg btn-primary btn-block" type="submit">Giriş</button> </form> </div><?php } ?> <!-- /container --> </html> [/PHP] [doublepost=1491433997,1491429608][/doublepost]DONE BITCHES [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Requests
User login
Top