wogloms Posted June 16, 2007 Share Posted June 16, 2007 can you help me? i'm making a php based login system and i need help checking usernames and passwords to see if they're correct. any help? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/ Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Could you post your code? All you would do for that is on the page where the POST data is sent to, you would just check it against the database. So lets say this is the page that they are taken to after they supply their login name and password. <?php //get their supplied login and pass $login = $_POST['login']; $pass = $_POST['password']; //See if they match the database $query = mysql_query("SELECT count(*) FROM users WHERE login='$login' AND password='$pass'") or die (mysql_error()); if (mysql_num_rows($query) > 0){ //login correct, register their session here. } else { //WRONG login/pass combo....deny them. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275931 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 where should i put the correct usernames and passwords in the code? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275934 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 where should i put the correct usernames and passwords in the code? Well...if the information they logged in with is correct, then the variables $login and $pass will hold the correct username and password. I'm not exactly sure what you mean though... Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275935 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 so, you would use an if statement? i'm not sure how to do them. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275938 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Could you be more specific? Use an if statement for what? I don't know exactly what your trying to figure out now. Are you wondering how to create a session that holds a unique ID that will tie to that user in the database so you can call their information on other pages? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275940 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 sorry. i meant to redirect the user if the username and password are correct. (basically, if they are the correct usernames and passwords) can you understand now? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275942 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 <?php //get their supplied login and pass $login = $_POST['login']; $pass = $_POST['password']; //See if they match the database $query = mysql_query("SELECT count(*) FROM users WHERE login='$login' AND password='$pass'") or die (mysql_error()); if (mysql_num_rows($query) > 0){ header("Location: http://www.url.com/"); //<-----This is where you are redirecting them to. //Your going to want to register a session or cookie here to finish the login process. } else { //WRONG login/pass combo....deny them. } ?> I added it for you. Just replace the url in the code to where you want the script to take them too if they have the right login info. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275947 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 one last question:where do you put the correct usernames and passwords? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275950 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Oh, I see what you are saying. You have to store them in a database. If you have a hosting plan, chances are that they have a control panel where you have access to creating your own database. I would suggest learning the basics of PHP and databases before taking on a project like this one. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275952 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Is this a type of website where many different users with different logins and passwords are being used? If it isn't, and there will always only be one username, and one password...then you don't need a database. You didn't really explain exactly what you were trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275953 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 well, sorry for the confusion. it would be for lots of people(about 30) would have a different login set(username and password) BUT it would have about 3 admin passwords.(for me, and my friend) does this help? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275955 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 Yeah...you would have to set up a database then. If you don't know how to do that, there are plenty of tutorials on it out there. Just google it, and you will find something. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275958 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 what should i google? i've searched a few variations and not got very good results. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275961 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 well, what would be the code for one login? i could that if necessary. Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275963 Share on other sites More sharing options...
pocobueno1388 Posted June 16, 2007 Share Posted June 16, 2007 If you do that, you won't be able to have the 30 or so users you were talking about. Unless everyone used the same exact username and password. You wouldn't be able to differentiate who was who. There are plenty of tutorials out there for login scripts. http://www.google.com/search?hl=en&q=PHP+login+script+tutorial&btnG=Search Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275966 Share on other sites More sharing options...
wogloms Posted June 16, 2007 Author Share Posted June 16, 2007 well, i could use javascript after they're logged in and they could enter an id number which would identify what user they were. (e.x. #1 could have 1, #2 could have 2, etc.) i COULD use one login could i have the code for 1 person, please? Quote Link to comment https://forums.phpfreaks.com/topic/55854-checking-passwords/#findComment-275967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.