Question: ( static void Main ( string [ ] args ) { string sTitle = Mason Solano ICA 9 ; string sPassword =

( static void Main(string[] args)
{
string sTitle = "Mason Solano ICA9";
string sPassword ="";
do
{
Console.Clear();
Console.CursorLeft =(Console.WindowWidth - sTitle.Length)/2; // display the title in the middle
Console.WriteLine(sTitle);
bool bValidPassword = true;
bool bLowercase = false;
bool bUppercase = false;
bool bSymbol = false;
int iDigitcount =0;
int iFirstdigit =-1;
bool bDifferentDigits = false;
bool bSpace = false;
do
{
Console.WriteLine("
Please enter a password to check: ");
sPassword = Console.ReadLine();
if (sPassword.Length <8)
{
Console.WriteLine("Password must be 8 characters long.");
bValidPassword = false;
}
foreach (char cCharacter in sPassword)
{
if (char.IsUpper(cCharacter))
{
bUppercase = true;
}
else if (char.IsLower(cCharacter))
{
bLowercase = true;
}
else if (!char.IsSymbol(cCharacter))
{
bSymbol = true;
}
else if (char.IsDigit(cCharacter))
{
int iDigit =(int)char.GetNumericValue(cCharacter); // Convert character to its digit value
if (iDigitcount ==0)
{
iFirstdigit = iDigit; // Store the first digit found
}
else if (iDigit != iFirstdigit)
{
bDifferentDigits = true; // Check if the digit is different from the first
}
iDigitcount++; // Increment digit counter
}
if (char.IsWhiteSpace(cCharacter))
{
bSpace = true;
Console.Write("Passowrd cannot contain a space.");
bValidPassword = false;
}
}
if (!bUppercase)
{
Console.WriteLine("Password doesn't contain an Uppercase.");
bValidPassword = false;
}
if (!bLowercase)
{
Console.WriteLine("Password must conatain a Lowercase.");
bValidPassword = false;
}
if (!bSymbol)
{
Console.WriteLine("Password must contain a symbol.");
bValidPassword = false;
}
if (iDigitcount <2)
{
Console.WriteLine("Password must conatin atleast 2 digits.");
bValidPassword = false;
}
else if (!bDifferentDigits)
{
Console.WriteLine("Password must be different digits.");
bValidPassword = true;
}
if (!bSpace)
{
Console.WriteLine("Password must not caontain spaces.");
bValidPassword = false;
}
if (bValidPassword)
{
Console.WriteLine("Password is valid.");
bValidPassword = true;
}
else
{
Console.WriteLine("Password is invalid.");
bValidPassword = false;
}
} while (!bValidPassword);
Console.Write("Do you want to run this program again y/n?: ");
} while (char.ToLower(Console.ReadKey().KeyChar)=='y');
}
} Fix this code so it gives me a valid password to end loop and invalid password

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!