Creating a simple login page that uses a phone number and password in Python can be done using a console-based script. A more complete and secure system would typically involve a database or secure storage system to hash and store the credentials, but for simplicity's sake, we'll just use a Python script here.
# A simple Python script to simulate a login system using phone number and password
# Let's define a simple user database as a dictionary with phone number as key and password as value
# Note: In a real system, you would store hashed passwords, not plain text for security reasons.
user_database = {
'+1234567890': 'password123',
'+0987654321': 'mypassword',
}
def login(phone, pwd):
# Check if the phone number exists in the user_database
if phone in user_database:
# Check if the password matches
if user_database[phone] == pwd:
return True
else:
print("Incorrect password.")
return False
else:
print("Phone number not found.")
return False
# Main program logic
while True:
print("Welcome to the login page.")
user_phone = input("Enter your phone number: ")
user_password = input("Enter your password: ")
# Attempt to login
successful_login = login(user_phone, user_password)
if successful_login:
print(f"Login successful for {user_phone}!")
# Upon successful login, you could break out of the loop or continue other tasks
# For demonstrative purposes, we'll just break out of the loop
break
else:
print("Login failed, please try again.")
# You may add a termination condition or limit the number of retries
Please note the following:
- This example script uses a simple dictionary to store user credentials, which is suitable only for demonstration purposes.
- In real-world applications, passwords should never be stored in plaintext. They should be hashed using a secure hashing algorithm (like bcrypt).
- This script doesn't handle input validation, error checking, or security concerns like brute-force attack prevention.
- In a production environment, you would use a more secure and sophisticated system involving a proper authentication system, a database for storing user credentials securely, and possibly additional layers like two-factor authentication (2FA).
- The
input() function is blocking and can be an issue for GUI or web-based applications. In such cases, frameworks like Flask, Django for web applications, or tkinter for GUI applications should be used.
For security reasons, please bear in mind that professional applications require much more secure and sophisticated account management systems than this simple example.