-
-
Save AntonGrig/dbeaa3fb610b0ee86dd50b863315f034 to your computer and use it in GitHub Desktop.
PwCS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace Password_security_checker | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Start: | |
int score = 0; | |
Console.WriteLine("Enter your password:"); | |
string password = Console.ReadLine(); | |
int length = password.Length; | |
Console.WriteLine("Repeat your password:"); | |
string repeatPassword = Console.ReadLine(); | |
if (length >= 8) | |
{ | |
score++; | |
} | |
else | |
{ | |
Console.WriteLine("Password is too short"); | |
goto Start; | |
} | |
if (password.Any(char.IsUpper)) | |
{ | |
score++; | |
} | |
if (password.Any(char.IsLower)) | |
{ | |
score++; | |
} | |
if (password.Any(char.IsDigit)) | |
{ | |
score++; | |
} | |
if (password.Any(char.IsSymbol)) | |
{ | |
score++; | |
} | |
if (password == repeatPassword) | |
{ | |
Console.WriteLine("Your password is: " + password); | |
} | |
else if (password != repeatPassword) | |
{ | |
Console.WriteLine("Password does not match"); | |
goto Start; | |
} | |
Console.WriteLine("Your password score is " + score); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clean coding tips:
#1: Remove empty spaces https://gist.github.com/AntonGrig/dbeaa3fb610b0ee86dd50b863315f034#file-code-cs-L5-L6
The correct way of formatting the code is putting a statement, and then the curly brace goes on the next line without any whitespaces.
Also, the lines of code should not be separated by more than 2 empty lines.
#2: using "goto"s is considered an anti-pattern https://gist.github.com/AntonGrig/dbeaa3fb610b0ee86dd50b863315f034#file-code-cs-L12. If you're using it then you need to rethink the strategy.
I suggest using while or do-while loop (tutorial: https://www.tutorialsteacher.com/csharp/csharp-do-while-loop)
e.g.