LOGIN SYSTEM #4: Login Function

 We created a database. We set up a register system. Now, all that's left is the login function. We need to set up a system where the user enters his credentials and the code checks the database to see if that pair of credentials exists. It allows the user if yes and sends a rejection message if the user-entered credentials does not exist. Coding this is no problem. 

First, lets create a menu that gives the user the option to register or login. A simple if-else statement is enough for this.






Something like this would be enough for now. If user inputs 1, it goes to the register function that we coded earlier. However, if he is a returning user, he needs to login. To code that:


The login code is similar to the username check we coded before. Here, we need to check both username and password. There are three ways by which we can say that the credentials are wrong.

  1. Username doesn't exist in any case
  2. Username doesn't exist in the specific given case
  3. Username exists but entered password doesn't match with database passwords. 
Since we have three rejection methods, we have three else statements with the rejection message. If the user enters correct data, however, there is a success message to say that credentials are right. For the success message to be showed, username needs to be in the database, it should be in the same case as entered and the password should be the same as in the database. The output looks like this:

Success O/P:




Failure O/P: (Case 2)


Failure O/P: (Case 3)




So, that's how you can set up your own basic credentials system. You could add to it to make it better by adding a GUI or adding other features but I hope this series gives you a basic understanding of how SQL integration with Python works. The entire code is here:  Source Code


For the last post in this series: The PYgrammer: LOGIN SYSTEM #3: Checking for repeating Username

If you want to check out some fun games: The PYgrammer: PYTHON GAMES COMPILATION


Comments