1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
polet [3.4K]
3 years ago
5

You have been asked to write a username validation program for a small website. The website has specific rules on what constitut

es a valid username, including:
All usernames must be between 8 and 15 characters long

Usernames can only contain alphabetic (a-z and A-Z) and numeric characters (0-9) - no special characters are allowed.

The first character in a username cannot be a digit
Usernames must contain at least one uppercase character
Usernames must contain at least one lowercase character
Usernames must contain at least one numeric character

Write a program that asks the user to enter in a username and then examines that username to make sure it complies with the rules above. Here's a sample running of the program - note that you want to keep prompting the user until they supply you with a valid username:

a.Please enter a username: foo
Username must be between 8 and 15 characters.

b.Please enter a username: fooooooooooooooooooo
Username must be between 8 and 15 characters.

c.Please enter a username: foo ooo ooo
Username must contain only alphanumeric characters.

d.Please enter a username: foooooooooo
Your username must contain at least one digit

e.Please enter a username: 1fooooooooo
The first character in your username cannot be a digit

f.Please enter a username: fooooooooo1
Your username must contain at least one uppercase character

g.Please enter a username: Fooooooooo1
Your username is valid!

Computers and Technology
1 answer:
umka21 [38]3 years ago
3 0

Answer:

#function to validate username

def valid_username(username):

   

   #checking is length is between 8 to 15

   length_valid=True

   if(len(username)<8 or len(username)>15):

       length_valid=False;

   

   #checking is string is alphanumeric

   alphanumeric=username.isalnum()

   

   #checking first_and_last Characters of string is not digit

   first_and_last=True

   if(username[0].isdigit() or username[len(username)-1].isdigit()):

       first_and_last=False

   

   #counting uppercase lowercase and numeric Characters in string

   uppercase=0

   lowercase=0

   numeric=0

   

   for i in username:

       if(i.isdigit()):

           numeric=numeric+1

       elif(i.isalpha()):

           if(i.isupper()):

               uppercase=uppercase+1

           else:

               lowercase=lowercase+1

               

   valid_no_char=True

   if(uppercase<1 or lowercase<1 or numeric<1):

       valid_no_char=False

           

 

   #printing the result

   print("Length of username: "+str(len(username)))

   print("All Characters are alpha-numeric: "+str(alphanumeric))

   print("First and last Character are not digit: "+str(first_and_last))

   print("no of uppercase characters in the username: "+str(uppercase))

   print("no of lowercase characters in the username: "+str(lowercase))

   print("no of digits in the username: "+str(numeric))

   

   #checking string is Valid or not

   if(length_valid and alphanumeric and first_and_last and valid_no_char):

       print("Username is Valid\n")

       return True

   else:

       print("username is invalid, please try again\n")

       return False

#loop runs until valid_username enterd by user

while(True):

   

   username=input("Enter a username: ")

   if(valid_username(username)):

       break

Explanation:

The code was created by considering all the required cases asked in the question.

In this program, I asked username from the user continuously until it enters a valid username

first it check for length of string

then check is string contains only alphanumeric characters

then first and last digit is or not

than no of uppercase lowercase and numeric character

using the above parameter declare username valid or not

You might be interested in
When an organization implements a major accounting software package, it also inherits the system of internal control that is bui
Genrish500 [490]

Answer:

potata

Explanation:

potato

3 0
3 years ago
Can someone please give me example of three types of loop in pascal (It has to has randomize in it too)
Lubov Fominskaja [6]

Sr.No Loop Type & Description
2 for-do loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
3 repeat-until loop Like a while statement, except that it tests the condition at the end of the loop body. (HOPE THIS HELPS!!)
3 0
3 years ago
what is the difference between the registry and server manager in reference to its management/configuration ?
Ksivusya [100]

Explanation:

Server manager perform various types management tasks in Microsoft window to manage remote severs without require any physical access. It enable remote desktop connection protocols. It basically use server manager for manage the server remotely.

Registry is very important as it store essential information about the window system and about its configurations. It is mainly use in Microsoft window for operating its system and applications. It also store low level settings in the system.

6 0
3 years ago
Which NIMS communication principle ensures that communications and information systems can be expanded to support any situation,
madam [21]

Answer: Portability

Explanation: National; approach to incident management(NIMS) principle named as portability is responsible for the supporting the system in any situation. It lets an individual to access the equipment that are familiar.

Portability helps in moving the flow of the communication and resources with easiness and information system can be extended till the requirement to support the incidental situation.

8 0
4 years ago
There are many food carts near Mars university. Mark and his friends regularly buy hot dogs from Jeff’s cart. Recently, Andrea o
Mama L [17]
Agreed with guy above thanks
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which process refers to starting up a computer?<br> is the process of starting a computer.
    9·2 answers
  • I am doing Microsoft Excel and I have do formulas, Can some please explain to me how do them?
    14·1 answer
  • Having network users login with a username and password is an example of:
    12·1 answer
  • A cashier distributes change using the maximum number of five-dollar bills, followed by one-dollar bills. Write a single stateme
    6·1 answer
  • Who invented the first antivirus software and when was it written?
    12·1 answer
  • A PC is not able to connect to a wired network. Pinging the loopback address is successful, but the gateway cannot be reached. O
    12·1 answer
  • Explain the procedure you will undertake to create a new partition​
    11·1 answer
  • তথ্য ও যোগাযোগ প্রযুক্তির প্রশ্ন(45)10 সংখ্যাটির সমতুল্য মান?
    14·1 answer
  • Which tab should you use to change the text font color in your presentation?
    15·1 answer
  • It is very easy to change data into charts<br> what is a Microsoft Excel Microsoft Outlook or both​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!