Mein C#-Code zum Erstellen eines neuen Passworts funktioniert nicht [Duplikat]C#

Ein Treffpunkt für C#-Programmierer
Guest
 Mein C#-Code zum Erstellen eines neuen Passworts funktioniert nicht [Duplikat]

Post by Guest »

Ich versuche, einen Code zu erstellen, der ein Passwort erstellt, das länger als 8 ist und mindestens ein Symbol enthält, aber wenn ich diesen Code ausführe, wird die Symbolbedingung ständig wiederholt, auch wenn das Passwort welche enthält.
Also was genau ist das Problem? und vielen Dank im Voraus

Code: Select all

 internal class Program
{
public static bool ContainSpaecial(string password)
{
string special = $"!@#$%^&*|/?`~';:()_+-=";

bool contains = password.Contains(special);
return contains;

}
static void Main(string[] args)
{
Console.WriteLine("please enter a password: ");
string password = Console.ReadLine();
string passwordcf;
bool containssymbol = ContainSpaecial(password);

while (password.Length < 8 ||  containssymbol == false)
{

if (string.IsNullOrEmpty(password))
{
Console.Write("please enter a password: ");
password = Console.ReadLine();
containssymbol = ContainSpaecial(password);
}
else if (password.Length < 8)
{
Console.Write("password is short, please try again: ");
password = Console.ReadLine();
containssymbol = ContainSpaecial(password);
}
else
{
Console.Write("password must contain one symbol at least: ");
password = Console.ReadLine();
containssymbol = ContainSpaecial(password);

}
}
Console.Write("please enter password again to confirm: ");
passwordcf = Console.ReadLine();
while (passwordcf != password)
{
if (!string.IsNullOrEmpty(passwordcf))
{
Console.Write("passwords does not match, please try again: ");
passwordcf = Console.ReadLine();
}
else
{
Console.Write("please enter password again to confirm: ");
passwordcf = Console.ReadLine();
}
}
Console.WriteLine("password created successfully!");

}
}
Ich denke, dass der Bool-Wert „containssymbol“ (der ein Bool-Wert ist, den ich erstellt habe, um zu überprüfen, ob das Passwort Symbole enthält oder nicht) nicht von „false“ in „true“ wechselt, weshalb die While-Schleife weiterhin eine Schleife durchläuft, aber ich Ich bin mir nicht sicher, wie ich es ändern soll, wenn ich von Anfang an Recht hatte.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post