Login.And.Register.System.Using.Python.mp4
The code snippet is a class called Validate that provides methods for validating and managing user registration, login, and account deletion. It uses the bcrypt library for password hashing and the re library for email validation. The class also includes methods for updating a JSON file with user data and checking if a username already exists.
validateObj = Validate()
validateObj.register_user("john", "password123", "[email protected]")
validateObj.login_user("john", "password123")
validateObj.delete_account("john")questionary---->for creating interactive prompts and questionnairesjson-------------->Used for parsing and generating JSON datarich.console--->enables rich text and beautiful formatting in the terminaltime.sleep------>used to pause the execution of the script for a specified number of seconds.bcrypt------------>to build a cryptographic hash of passwordsre------------------>used for searching, matching, and manipulating strings based on specific patterns
username(string): The username entered by the user.password(string): The password entered by the user.email(string): The email entered by the user.
- The
Validateclass checks if the JSON file "data.json" exists. If not, it creates a new file with an empty "gamedata" dictionary. - The
hash_passwordmethod takes a password as input, generates a salt, and hashes the password using bcrypt. - The
update_jsonmethod updates the "gamedata" dictionary in the JSON file with the username, hashed password, and email. - The
validate_usernamemethod checks if the username is valid (not empty and contains only lowercase letters) and if it already exists in the JSON file. - The
validate_passwordmethod checks if the password meets certain criteria (minimum length, contains a number, lowercase letter, and uppercase letter). - The
validate_emailmethod uses a regular expression to validate the email format. - The
register_usermethod validates the username, password, and email, hashes the password, and updates the JSON file with the user data. - The
login_usermethod checks if the username exists in the JSON file, retrieves the hashed password, and compares it with the entered password using bcrypt. - The
delete_accountmethod checks if the username exists in the JSON file, deletes the user data from the "gamedata" dictionary, and updates the JSON file. - The
registerfunction prompts the user to enter a username, password, and email, validates the inputs, and calls theregister_usermethod. - The
loginfunction prompts the user to enter a username and password, calls thelogin_usermethod, and displays a welcome message if successful. - The
delete_accountfunction prompts the user to enter a username and password, calls thelogin_usermethod to validate the credentials, and calls thedelete_accountmethod to delete the user account.
- The
register_usermethod returnsTrueif the registration is successful, andFalseif any validation error occurs. - The
login_usermethod returnsTrueif the login is successful, andFalseif the username or password is incorrect. - The
delete_accountmethod returnsTrueif the account is successfully deleted, andFalseif the username is not found in the JSON file.