Making the register system is one thing, but how do we make sure that two people do not use the same username. There are two things we need to consider while doing this:
- SQL is case insensitive, so as far as SQL is concerned, ABC and abc are the same.
- However, for a username, case sensitivity must be taken into account.
So first, we search the SQL database for the username and get any rows with that username (case not taken into account) and store it in data. If the length of data is 0, then there is no row, so we do not need to do any check and can directly add the username and password to the database. But, if len(data) is not 0, then we need to check for case. So, we use Python's equality operator to do the check as it returns True only if case is also equal. Now, let's check how it works:
Case 1: Username exists:-
Case 2:- Username doesn't exist:-
Here, though the text by-itself is the same, the case is different and therefore, we can take it as a new username. Let's check the database to see if it is updated.
Comments
Post a Comment