Question

In: Computer Science

C# Create an application that asks the user to enter their new password. The password must...

C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.

Solutions

Expert Solution

SOLUTION-
I have solve the problem in C# code with comments and screenshot for easy understanding :)

CODE-

using System;

namespace ConsoleApp // Project name
{
class Program
{
class InvalidPasswordException : Exception
{

public InvalidPasswordException()
: base(String.Format("Invalid Passwrod, Password length should be greater then 6 letters"))
{

}

}

class Password
{
static void Main(string[] args)
{
while (true)
{
try
{
// read input
Console.Write("Enter password must be at least 6 characters long: ");
string pass = Console.ReadLine();
// check password length
if (validatePassword(pass))
{
Console.WriteLine("Done.");
break;
}
}
catch (InvalidPasswordException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("Try again.");
}
}
Console.ReadKey();

}

private static bool validatePassword(string pass)
{
// if password length is less then 6
if (pass.Length < 6)
{
// throw exception
throw new InvalidPasswordException();
}
return true;
}
}
}
}

Output:

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
C# Create a console application that asks the user for two numbers in the range 0-255...
C# Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
c++ Develop a program that validates a password entered by a user. The password must meet...
c++ Develop a program that validates a password entered by a user. The password must meet the following criteria: Be at least six characters long. Contain at least one uppercase and at least one lowercase letter. Have at least one digit. Write a program that asks for a password and then verifies that it meets the stated criteria. If it does not, the program should display a message telling the user why and ask for another password. The program should...
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
1) Write Java application that asks the user to enter the cost of each apple and...
1) Write Java application that asks the user to enter the cost of each apple and number of apples bought. Application obtains the values from the user and prints the total cost of apples. 2) Write a java application that computes the cost of 135 apples, where the cost of each apple is $0.30. 3)Write a java application that prepares the Stationery List. Various entries in the table must be obtained from the user. Display the Stationary list in the...
Create an application named Rusty2 that asks the user for the dealer cost of a car,...
Create an application named Rusty2 that asks the user for the dealer cost of a car, and the cleaning cost, and then displays the retail cost. Your application should simply send the dealer cost and cleaning cost to the getRetailPrice method in the Dealership class to obtain the retail cost. here below is the dealership class code amd meed to create rusty2 code import java.util.Calendar; public class Dealership { // public static final class variables public static final int YEAR_STARTED...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT