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
matrenka [14]
3 years ago
13

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:

Computers and Technology
1 answer:
Semmy [17]3 years ago
5 0

Answer:

Check the explanation

Explanation:

Python program to validate username and passwords and if invalid then fix the password to generate valid passwords

'''

import string

import random

# function to validate username

def username_validation(username):

             

              lowercase_letters = string.ascii_lowercase # string of all lowercase letters

              uppercase_letters = string.ascii_uppercase # string of all uppercase letters

              digits = string.digits

                           

              num_uppercase = 0

              num_lowercase = 0

              num_digits = 0

              num_invalid = 0

                           

              for letter in username:

                             if letter in lowercase_letters:

                                            num_lowercase = num_lowercase + 1

                             elif letter in uppercase_letters :

                                            num_uppercase = num_uppercase + 1

                             elif letter in         digits:

                                            num_digits = num_digits + 1

                             else:

                                            num_invalid = num_invalid + 1

             

             

              valid_start_end = not(username[0] in digits) and not(username[-1] in digits)

             

              print('* Length of username: %d'%(len(username)))

              print('* All characters are alpha-numeric: '),

              print(num_invalid == 0)

              print('* First & last characters are not digits: '+str(valid_start_end))

              print('* # of uppercase characters in the username: %d' %(num_uppercase))

              print('* # of lowercase characters in the username: %d' %(num_lowercase))

              print('* # of digits in the username: %d' %(num_digits))

             

              return(valid_start_end,num_uppercase,num_lowercase,num_digits,num_invalid)

# function to validate password  

def password_validation(username,password):

              while True:

                             (username_contained,num_lowercase,num_uppercase,num_special_chars,num_digits,num_invalid) = password_validation(username,password)

                             if(len(password) >= 8 and (not username_contained) and num_lowercase > 0 and num_uppercase > 0 and num_special_chars > 0 and num_invalid == 0):

                                            return password

             

                             if num_lowercase == 0:

                                            pos = random.randint(0,len(password)-1)

                                            letter = random.randint(0,len(lowercase_letters)-1)

                                            temp_password = password[0:pos] + lowercase_letters[letter]+ password[pos:]

                                            password = temp_password

                                            print('')

                                            print('* Adding a random lowercase character at a random position: '+password)

                                           

                             if num_uppercase == 0:

                                            pos = random.randint(0,len(password)-1)

                                            letter = random.randint(0,len(uppercase_letters)-1)

                                            temp_password = password[0:pos] + uppercase_letters[letter]+ password[pos:]

                                            password = temp_password

                                            print('* Adding a random uppercase character at a random position: '+password)

                                           

                             if num_special_chars == 0:

                                            pos = random.randint(0,len(password)-1)

                                            letter = random.randint(0,len(special_chars)-1)

                                            temp_password = password[0:pos] + special_chars[letter]+ password[pos:]

                                            password = temp_password

                                            print('* Adding a random special character at a random position: '+password)

                           

                             if num_digits == 0:

                                            pos = random.randint(0,len(password)-1)

                                            letter = random.randint(0,len(digits)-1)

                                            temp_password = password[0:pos] + digits[letter]+ password[pos:]

                                            password = temp_password

                                            print('* Adding a random digit character at a random position: '+password)

                                           

                             if num_invalid > 0:

                                            i=0

                                            while i <len(password):

                                                           if password[i] not in valid_letters:

                                                                          temp_password = password[0:i] + password[i+1:]

                                                                          password = temp_password

                                                           else:

                                                                          i = i +1

                                            print('* Removing the invalid character from

                             (username_contained,num_lowercase,num_uppercase,num_special_chars,num_digits,num_invalid) = password_validation(username,password)

                             if(len(password) >= 8 and (not username_contained) and num_lowercase > 0 and num_uppercase > 0 and num_special_chars > 0 and num_invalid == 0 and num_digits > 0):

                                            break

                             else:

                                            print('* Length of password: %d' %(len(password)))

                                            print('* Username is part of password : '+str(username_contained))

                                            print('* # of uppercase characters in the password: %d' %(num_uppercase))

                                            print('* # of lowercase characters in the password: %d' %(num_lowercase))

                                            print('* # of digits in the password: %d' %(num_digits))

                                            print('* # of special characters in the password: %d'%(num_special_chars))

                                            print('* # of invalid characters in the password: %d' %(num_invalid))

                                                         

                                            print('Password is invalid, please try again')

                                            choice = raw_input('\nWould you like us to fix your password for you? ')

                                            if choice.lower() == 'yes':

                                                           password = password_fixer(username,password)

                                                           print('Your new password is '+password)

                                            else:      

                                                           password = raw_input('\nEnter a password: ')

                           

              print('Password is valid!')              

#call the main function  

if __name__ == "__main__":

              main()  

#end of program

###The full code is more than 5000 characters which is above brainly character limit, so kindly check the below image for the complete code screenshot.

You might be interested in
Assume that speed = 10 and miles = 5. What is the value of each of the
Assoli18 [71]

a. speed + 12 - miles * 2  = 10 + 12 - 5 * 2. With order of operations, we do the multiplication first so the equation is now 10 + 12 - 10 = 22 - 10 = 12

b. speed + miles * 3  = 10 + 5 * 3 and again, order of operations gives us 10 + 15 = 25

c. (speed + miles) * 3  = (10 + 5) * 3 = 15 * 3 = 45

d. speed + speed * miles + miles  = 10 + 10 * 5 + 5 = 10 + 50 + 5 = 60 + 5 = 65

e. (10 – speed) + miles / miles = (10 - 10) + 5 / 5 = 0 + 5 / 5 = 5 / 5 = 1

5 0
4 years ago
How to write a C++ program that allows a user to enter their rating of the three movies in the Dark Knight Trilogy and then disp
8_murik_8 [283]

The program is an illustration of arrays.

Arrays are used to hold multiple values in one variable.

The program in C++ where comments are used to explain each line is as follows:

#include <iostream>

using namespace std;

int main(){

   //This declares an array of three elements for the three ratings

   int ratings[3];

   //This initializes the sum of the ratings to 0

   int total = 0;

   //The following iteration gets input for the three ratings

   for(int i = 0; i<3;i++){

       cin>>ratings[i];

       //This calculates the sum of all inputs

       total+=ratings[i];

   }

   //This declares and initializes the lowest and the highest ratings

   int lowest = ratings[0], highest = ratings[0];

   //This iterates through the array

   for(int i = 1; i<3;i++){

       //The following if condition determines the lowest rating

       if (lowest > ratings[i]){    lowest = ratings[i];        }

       //The following if condition determines the highest rating

       if (highest < ratings[i]){            highest = ratings[i];        }

   }

   //This prints the output header

   cout<<"The ratings are: ";

   //The following iteration prints the three ratings

   for(int i = 0; i<3;i++){

       cout<<ratings[i]<<" ";   }

   //The prints the highest ratings

cout<<endl<<"Highest: "<<highest<<endl;

   //The prints the lowest rating

   cout<<"Lowest: "<<lowest<<endl;

   //The prints the average rating

cout<<"Average: "<<total/3<<endl;

   return 0;

}

At the end of the program, the ratings entered, the highest rating, the lowest rating, and the average of the ratings are printed.

See attachment for sample run

Read more about similar programs at:

brainly.com/question/13261254

8 0
3 years ago
Does scope frequently changes during a project?<br>​
lesya [120]

Answer:

no

Explanation:

6 0
3 years ago
Read 2 more answers
Write a static method that implements a recursive formula for factorials. Place this method in a test program that allows the us
matrenka [14]

Answer:

Written in Java

import java.util.*;

public class Main {

  public static int fact(int n) {

     if (n == 1)

        return n;

     else

        return n * fact(n - 1);

  }

  public static void main(String[] args) {

     int num;

     Scanner input = new Scanner(System.in);

     char tryagain = 'y';

     while(tryagain == 'y'){

     System.out.print("Number: ");

     num = input.nextInt();

     System.out.println(num+"! = "+ fact(num));

     System.out.print("Try another input? y/n : ");

     tryagain = input.next().charAt(0);

}        

  }

}

Explanation:

The static method is defines here

  public static int fact(int n) {

This checks if n is 1. If yes, it returns 1

     if (n == 1)

        return n;

If otherwise, it returns the factorial of n, recursively

     else

        return n * fact(n - 1);

  }

The main method starts here. Where the user can continue executing different values of n. The program keep prompting user to try again for another number until user signals for stoppage

  public static void main(String[] args) {

This declares num as integer

     int num;

     Scanner input = new Scanner(System.in);

This initializes tryagain as y

     char tryagain = 'y';

This checks if user wants to check the factorial of a number

     while(tryagain == 'y'){

This prompts user for input

     System.out.print("Number: ");

This gets user input

     num = input.nextInt();

This passes user input to the function and also prints the result

     System.out.println(num+"! = "+ fact(num));

This prompts user to try again for another value

     System.out.print("Try another input? y/n : ");

This gets user response

     tryagain = input.next().charAt(0);

}        

Download txt
4 0
3 years ago
Your boss asks you to transmit a small file that includes sensitive personnel data to a server on the network. The server is run
mel-nik [20]

Answer:

a. Telnet transmissions are not encrypted.

Explanation:

Indeed, since <em>Telnet transmissions are not encrypted,</em> all the information sent, and even the characters typed in the telnet console are sent in clear text.

This is a security issue, since any other device in the same network will receive a copy of the information (packets) sent. For default, all the devices, except for the server expecting to receive the information, will discard the packets. However it is easy to actively <em>listen </em>and keep those packets, wich will contain the information in plain text and human readable.

4 0
3 years ago
Other questions:
  • Mobile devices typically come pre installed with standard apps like web browsers , media players, and mapping programs true or f
    9·1 answer
  • loop Write a program to read a list of exam scores given as integer percentages in the range 0 to 100. Display the total number
    5·1 answer
  • "what should you do if the system continually reboots and you can't read the error message produced on a blue screen
    11·2 answers
  • A way to minimize technical problems with your computer
    14·1 answer
  • What is the leading use of computers
    15·2 answers
  • when you are editing a word precessing document, what will tell the word processing program where in the document you are making
    10·1 answer
  • Decrypt this message: P ht uva h zwf
    13·1 answer
  • What is assembler? What is Compiler?What is interpreter?
    9·2 answers
  • What would be printed to the screen when the following program is run?
    11·1 answer
  • You discover that the lecturers will be using the laptops for online and video lecturing, and you see the need to upgrade the RA
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!