• Home
  • Get Started
  • Updates
  • Support
  • Shop
  • Pricing
  • AI News
Get Started
  • Login
  • Register
Neuraldemy
Cart / 0.00$

No products in the cart.

No Result
View All Result
Get Started
Neuraldemy
Get started
Home Free

How To Create A Signup And Login Form In Python With Validation

Python Tutorial For Registration form and Login Form

Amritesh Kumar by Amritesh Kumar
November 29, 2023 - Updated on August 1, 2024
in Python
Reading Time: 6 mins read
A A
How To Create A Signup And Login Form In Python With Validation

In this post, you will see how you can design your own signup and login form in Python with user validation and start building your own apps. Afterwards, I have also included the email validation step. The password encryption step is not included, but you can rely on a third-party library.

Prerequisites:

  1. Familiarity with Python functions.
  2. Familiarity with Regex.
  3. Understanding of user input validation.
  4. Understanding of error validation.

What You Will Learn:

  1. How to create a signup form in Python
  2. How to create a login form in Python
  3. How to use regex for email validation
  4. A database to manage users and allow users to manage their data – account deletion.
  5. Age validation

So, let’s get started.

First of all, we are going to import the regex for email validation and create a database. Here I am using a simple dictionary but you can use Pandas or other database tools based on SQL as per the projects this is sufficient to show you how you can interact with the database.

import re
#create a database for users 
users = {}
Code language: Python (python)

Next, we are going to write a function to allow users to sign up:

# create a signup form
def signup():
    
    details = {}
    
    # asking for name
    name = input("Enter your name")
    details["Name"] = name

    # asking for age and verifying
    try:
        age = int(input("Enter your age. You must be at least 13."))
    except ValueError:
        print("Only numbers are allowed")
    else:
        if age < 13:
            print("You must be at least 13")
        else:
            details["Age"] = age
    
    # asking for email and verifying 
    email = input("Enter your email.")
    # Create a Regex for Email Addresses
    emailRegex = re.compile(r'''(
                        
                        [a-zA-Z0-9._%+-1]+   #username
                        @                    # @symbol
                        [a-zA-Z0-9.-]+       #domain name
                        (\.[a-zA-Z]{2,4})    #dot-something
                        )''', re.VERBOSE)    
    e = []
    f = emailRegex.search(email)
    if f == "None":
        print("Enter an email")
    else:
        try:
            e.append(f.group())
            if e[0] in users:
                print("This email is already taken")
            else:
                details["Email"] = e[0]
        except AttributeError:
            print("One email address is needed!")
        
    # enter address
    address = input("Enter your address")
    details["Address"] = address
    
    # enter username 
    username = input("Enter your username")
    if username in users:
        username = input("Enter a different username")
        details["Username"] = username
    else: 
        details["Username"] = username
    
    # enter password -- You can also encrypt and decrypt the password using third party libarary
    password = input("Enter your password")
    details["Password"] = password

    # updating our database   
    users.update({username : details})
    print("\n")
    print("Your Details Are:")
    print(details)
Code language: Python (python)

Next, we are going to write a code to allow users to log in:

# to allow users to login
def login():
    username = input("Enter your username")
    if username not in users:
        print("You don't have an account. Please create one")
    else: 
        password = input("Enter your password")
        if password != users[username]["Password"]:
            print("Password did not match. Try again")
        else:
            print("You are successfully logged in") # you can input the process you want to start here. 
Code language: Python (python)

Finally, a code to allow users to delete or remove their data:

# A function to allow users to deleted their accounts
def delete():
    username = input("Enter your username")
    if username not in users:
        username = input("Enter your username")
    else:
        users.pop(username)
        print("Account Deleted")
Code language: Python (python)

That’s it. Hope this was helpful. Feel free to drop your questions below. You must keep in mind password encryption if you creating a real-world project. Now if you want to move to a new project then see how you can create an e-commerce app in Python here.

Please note: the code above may not organize well on mobile devices so please use a laptop and code along to learn faster.

Tags: Python ProjectsPython Tutorial
Next Post

19 Basic Machine Learning Questions

Amritesh Kumar

Amritesh Kumar

I believe you are not dumb or unintelligent; you just never had someone who could simplify the concepts you struggled to understand. My goal here is to simplify AI for all. Please help me improve this platform by contributing your knowledge on machine learning and data science, or help me improve current tutorials. I want to keep all the resources free except for support and certifications. Email me @amriteshkr18@gmail.com.

Related Posts

pickle module in python

Pickle Module In Python: A Comprehensive Guide for Beginners

Python Os Module

Python OS Module: A Comprehensive Guide for Beginners

Install Miniconda on Windows (The EASIEST Way! )

TensorFlow Simplified Guide For Beginners

Create A To-Do-List App In Python: Complete Tutorial

Notes App In Python: Complete Tutorial

Next Post
19 Basic Machine Learning Questions

19 Basic Machine Learning Questions

E-commerce App In Python – User Facing

E-commerce App In Python - User Facing

Notes App In Python: Complete Tutorial

Notes App In Python: Complete Tutorial

  • Customer Support
  • Get Started
  • Ask Your ML Queries
  • Contact
  • Privacy Policy
  • Terms Of Use
Neuraldemy

© 2024 - A learning platform by Odist Magazine

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Home
  • Get Started
  • Updates
  • Support
  • Shop
  • Pricing
  • AI News
  • Login
  • Sign Up
  • Cart
Order Details

© 2024 - A learning platform by Odist Magazine

This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
0