php - Register and Login Multiple Users With the Same Firstname and Lastname -
i'm working on register-login system, i'm facing following problem: - can have 2 (or more) employees same firstname , same lastname, , possibly same password, each located either in same location, or different. when i'm trying register them, obviously, there aren't problems, when want login them, problems arise.
users table:
id int (11) a_i p_k, firstname varchar (50), lastname varchar(50), password varchar(150)
register.php
<?php $db = new pdo('mysql:host=127.0.0.1;dbname=xxx', 'root', ''); $fname = isset($_post['fname]) ? $_post['fname'] : ''; $lname = isset($_post['lname']) ? $_post['lname'] : ''; $pass = isset($_post['pass']) ? password_hash($_post['pass'], password_default) : ''; $stmt = $db->prepare('insert users set fname=?,lname=?,pass=?'); $stmt->execute([$fname,$lname,$pass]); ?> <form method="post"> <input type="text" name="fname"/><br/> <input type="text" name="lname"/><br/> <input type="password" name="pass"/><br/> <input type="submit" value="register"/> </form>
let's following users register:
fname=aaa lname=bbb pass=123456 // password_hash(123456) = hash1 fname=aaa lname=bbb pass=123456 // password_hash(123456) = hash2
login.php
<?php $db = new pdo('mysql:host=127.0.0.1;dbname=xxx', 'root', ''); $fname = isset($_post['fname]) ? $_post['fname'] : ''; $lname = isset($_post['lname']) ? $_post['lname'] : ''; $pass = isset($_post['pass']) ? $_post['pass'] : ''; $stmt = $db->prepare('select * users fname=? , lname=?'); $stmt->execute([$fname,$lname]); while ($row = $stmt->fetch(pdo::fetch_obj)){ if (password_verify($pass, $row->pass)) { echo $row->fname,' ',$row->lname,'<br/>',$row->pass,"<br/>"; // header('location: app.php'); } } ?> <form method="post"> <input type="text" name="fname"/><br/> <input type="text" name="lname"/><br/> <input type="password" name="pass"/><br/> <input type="submit" value="login"/> </form>
if run login.php script, following output:
aaa bbb $2y$10$onkd3s06bououyeh0/i9be4jry1g8uixgb3lxwrobzfzzywhka6eq (== hash1) aaa bbb $2y$10$ss0n1ibypn4lg2vlp90yc.vh109y1lq54x0bi/tgs242hn/vkgwvi (== hash2)
and question is, how can differentiate 2 users, can log in in app.php page, must display credentials , other personal infos, differs 1 user another? thanks!
le: if try limit 1
login query, display first record found in db.
if users have same firstname, same lastname , same password, can't decide user database correct. need give them 1 unique part. maybe loginname or emailaddress
Comments
Post a Comment