// C# implementation of User Authentication
// Include namespace system
using
System;
using
System.Text.RegularExpressions;
public
class
GFG
{
public
const
String NAME =
"GEEKSFORGEEKS"
;
public
const
String USERNAME =
"GEEKS"
;
public
const
String PASSWORD =
"Geeks@123"
;
public
static
bool
SignUp(String name, String userName, String password)
{
// Verify password length
if
(password.Length < 8 || password.Length > 16)
{
Console.WriteLine(
"Password must be in range of 8-16 characters."
);
return
false
;
}
Regex regex =
new
Regex(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]+"
);
if
(regex.Match(password).Value==
""
)
{
Console.WriteLine(
"Password must contains alphanumeric characters and atleast 1 special symbol."
);
return
false
;
}
return
true
;
}
public
static
bool
Login(String userName, String password)
{
if
(userName == USERNAME && password == PASSWORD)
{
return
true
;
}
Console.WriteLine(
"Enter Valid Username Or Password!"
);
return
false
;
}
public
static
void
Main(String[] args)
{
// Try SignUp With Invalid Password (Length < 8)
Console.WriteLine(
"User 1 : "
);
if
(GFG.SignUp(NAME, USERNAME,
"Geeks12"
))
{
Console.WriteLine(
"Account Created Successfully."
);
}
// Try SignUp With Invalid Password (Excluding Special Symbol)
Console.WriteLine(
"User 2 : "
);
if
(GFG.SignUp(NAME, USERNAME,
"Geeks123"
))
{
Console.WriteLine(
"Account Created Successfully."
);
}
// With Valid Password
Console.WriteLine(
"User 3 : "
);
if
(GFG.SignUp(NAME, USERNAME, PASSWORD))
{
Console.WriteLine(
"Account Created Successfully."
);
}
// With Wrong Username Or Password
Console.WriteLine(
"User 2 : "
);
if
(GFG.Login(USERNAME,
"Geeks123"
))
{
Console.WriteLine(
"Log In Successful."
);
}
// With Valid Username And Password
Console.WriteLine(
"User 3 : "
);
if
(GFG.Login(USERNAME, PASSWORD))
{
Console.WriteLine(
"Log In Successful."
);
}
}
}