Search the Community
Showing results for tags 'login/registration'.
-
Hey Guys, I am in the beginning stages of creating a user login / register system for my website. currently, i am working on the conditionals to make sure the information logged in is proper , either matching the DB of my users or spitting an error array , letting my users know that either they need to enter both a valid username & pass or that the info entered does not match the Database. i have created a few functions that clean up the $_POST variables using mysql_real_escape_string: and my main function login(); function sanitize($data) { return mysql_real_escape_string($data); } function user_id_from_username($username){ $username = sanitize($username); return (mysql_result(mysql_query(" SELECT `user_id` FROM `users` WHERE `username`= '$username'"), 0 , 'user_id')); } function login($username, $password){ $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); return(mysql_result(mysql_query(" SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false; } and the conditionals to check the parameters given: if (empty($_POST) === false) { $username = $_POST['loginname']; $password = $_POST['loginpass']; if (empty($username) === true || empty($password) === true) { $errors[] = 'You need to enter a valid Username & Password'; } else if (user_exists($username) === false ) { $errors[] = ' Sorry we could not find this user info in our userbase.'; } else if (user_active($username) === false ) { $errors[] = 'This account still needs to be activated'; } else { $login = login($username, $password); if ($login === false) { $errors[] = ' The Username / Password combination you entered is incorrect.'; } else { echo 'Login Ok!!'; Now finally my issue : When i click login all of my conditionals work except the most important one. When I input a working username and password i am given the same error from my array that the combination is not correct. so its finding the username but the password is not matching and accepting ? any suggestions ? i have been trying to figure this out for a minute. Thanks guys!. edit: (just wanted to add: sorry mods for all caps in title, tried to go back and edit but was to late)
- 10 replies
-
- php
- login/registration
-
(and 3 more)
Tagged with: