Question

Write an infinite while loop that asks the user for their username and password. The loop...

Write an infinite while loop that asks the user for their username and password. The loop only stops if the username and password for the user are correct. There are only 2 users: the first user’s username is user123 and their respective password is passwrd1, the second user’s username is user234 and their respective password is passwrd2.

Expected output/input when loop is to stop:

Enter username: user123

Enter password: passwrd1

Welcome user123

!Expected output/input when loop continues:Enter username: user234

Enter password: passwrd1

Sorry, username or password is incorrect. Please try again.

Enter username:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: here is the answer for your question :

since any programming language is not mentioned here, so i am doing it in python. if you need any more help , provide comment below

code in python:


u1="user123"
p1="passwrd1"

u2="user234"
p2="passwrd2"


while(True):
username=str(input("Enter username:"))
password=str(input("Enter password:"))
if username== u1 and password==p1 :#checking username and password for user1
print("Welcome {}".format(username))
break
elif username== u2 and password==p2 :#checking username and password for user2
print("Welcome {}".format(username))
break
else:
print("Sorry, username or password is incorrect. Please try again.")

-----------------------------------------------------------------------------------------------------------------------------------

code snippet:

-----------------------------------------------------------------------------------------------------------------------------------

code output:

----------------------------------------------------------------------------------------------------------------------------------

I hope this would help you out

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
Write an infinite while loop that asks the user for their username and password. The loop...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Username and password verification with infinite while loop

    javascriptWrite an infinite while loop that asks the user for their username and password. the loop only stops if the username and password for the user are correct. there  2 users or more.

  • in python 5.23 Login Create a program that prompts the user for a username and password....

    in python 5.23 Login Create a program that prompts the user for a username and password. The correct username should be python and the correct password should be csci 135. See below for example output. (Different messages depending on if user name or password are correct.) Only allow the user to make 3 attempts. Welcome to my secret program! Please enter your username: Trish Please enter your password: Duce Invalid username and password Please enter your username: Trish Please enter...

  • Write a code using python that simulates a Registration of a Username and Password with the...

    Write a code using python that simulates a Registration of a Username and Password with the following conditions the user can set its username display "Input username" input Username display "Input Password" input Password The password must be at least 5 characters and no longer than 10 characters if the password doesn't follow this instructions Display "Can't accept this password" once the password its stored Verify that the program works by Testing it input username Input Password The user has...

  • Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need...

    Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need to use the best data structure to store the data you read from UD.txt for efficient processing. You can accomplish these tasks with Dictionary or List. The data file (UD.txt) : FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave,Dcon,dcf987, BHYW4fw Dell,Grant,dgr803,Sb83d2d Mike,Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt Give the following options: A: Search by...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • Write a piece of code that enters a loop and asks the user to input anon-negative...

    Write a piece of code that enters a loop and asks the user to input anon-negative number. If the user enters a negative number, the code goes back into the loop and asks the user again to enter a non-negative number. The code keeps going back into the loop until the user enters a non-negative number. Notice that the code enters the loop at least once. This is an application of 1 to N loop.Therefore, use a Do While statement.

  • Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks...

    Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • Hashmap concept

    HashMap:  We can use a HashMap to store key value pairs.  Reminder that only reference types can be used as the key or value.  It you want to use a number as the key then an Integer data type could be used but not an int primitive data type.Create a class called Login which contains a HashMap as a private attribute.  It should also have an instance method called loadCredentials which accepts the two arrays.  It will load the HashMap...

  • Design a Do-While loop that asks the user to enter two numbers. The numbers should be...

    Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat; otherwise it should terminate. using visual basic

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT