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
Anyone help me with number 41.
Katarina [22]
It is te = t I yhink
8 0
3 years ago
List 5 ways by which Artificial intelligence (AI) can be used to drive our business.​
andreyandreev [35.5K]

Answer:

start a website

Explanation:

true

5 0
2 years ago
If you change a column header in your data source, what would you press to ensure that the data is synced as expected?
kobusy [5.1K]

You should press the Match Fields to ensure that the data is synced as expected.

8 0
2 years ago
Kevin is a DJ and has a passion for creating and modifying audio tracks. Which application software facilitates him in his passi
stiv31 [10]
B. Multimedia software
5 0
3 years ago
Write a class called point that represents a point in 2d plane.
USPshnik [31]

In this way, writing the code in C++ we can say that it will be possible to make the coordinates on the planes.

<h3>Writing the code we have:</h3>

<em>#include <iostream></em>

<em>#include <cmath></em>

<em>#include <iomanip></em>

<em>using namespace std;</em>

<em>class Point{</em>

<em>private:</em>

<em>float x;</em>

<em>float y;</em>

<em>public:</em>

<em>Point(){ </em>

<em>x = y = 0;</em>

<em>}</em>

<em>Point(float x, float y){ </em>

<em>this->x = x;</em>

<em>this->y = y;</em>

<em>}</em>

<em>float getX(){ </em>

<em>return x;</em>

<em>}</em>

<em>float getY(){</em>

<em>return y;</em>

<em>}</em>

<em>float getDistance(){</em>

<em>return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2));</em>

<em>}</em>

<em>string toString(){ </em>

<em>return "("(x1, y)","(x2, y2)")";</em>

<em>}</em>

<em>};</em>

See more about C code at brainly.com/question/17544466

#SPJ1

7 0
2 years ago
Other questions:
  • To arrange data in alphabetical order quickly, you can _____ the data.
    7·2 answers
  • )in the link based implementation of the ADT sorted list what is the worst case time efficiency of the remove method?
    7·1 answer
  • Ranges of IP address that anyone can use for their internal networks are known as ______.
    8·2 answers
  • you are concerned with security at your company and want to implement a technology that requires no configuring on the users sid
    15·1 answer
  • Most computers and many mobile devices, such as smartphones and portable media players, can connect to which kind of network?
    11·1 answer
  • Which components of the​ five-component model is commonly thought of as the​ "bridge" that links the computer side of the model
    13·1 answer
  • You are a database administrator. Chantelle comes to you asking for help on how to access all the data in one row of the databas
    11·1 answer
  • What is the major difference between the intranet and extranet?
    11·1 answer
  • Why doesn't the ad load ?
    9·2 answers
  • in the future, mobile technologies are expected to be used more than desktop computers today. what other improvements are helpin
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!