Skip to content

Instantly share code, notes, and snippets.

@nirinium
Created August 30, 2019 03:39
Show Gist options
  • Save nirinium/ef3cfb66f861f571d80a06a60c947ec7 to your computer and use it in GitHub Desktop.
Save nirinium/ef3cfb66f861f571d80a06a60c947ec7 to your computer and use it in GitHub Desktop.
validators
private bool StringValidator(string input)
{
string pattern = "[^a-zA-Z]";
if (Regex.IsMatch(input, pattern))
{
return true;
}
else
{
return false;
}
}
//validate integer
private bool IntegerValidator(string input)
{
string pattern = "[^0-9]";
if (Regex.IsMatch(input, pattern))
{
return true;
}
else
{
return false;
}
}
private void ClearTexts(string user, string pass)
{
user = String.Empty;
pass = String.Empty;
}
internal bool IsLoggedIn(string user, string pass)
{
if (string.IsNullOrEmpty(user))
{
MessageBox.Show("Enter the user name!");
return false;
}
else if (StringValidator(user) == true)
{
MessageBox.Show("Enter only text here");
ClearTexts(user, pass);
return false;
}
else
{
if (Username != user)
{
MessageBox.Show("User name is incorrect!");
ClearTexts(user, pass);
return false;
}
else
{
if (string.IsNullOrEmpty(pass))
{
MessageBox.Show("Enter the passowrd!");
return false;
}
//check password is valid
else if (IntegerValidator(pass) == true)
{
MessageBox.Show("Enter only integer here");
return false;
}
//check password is correct
else if (Userpassword != pass)
{
MessageBox.Show("Password is incorrect");
return false;
}
else
{
return true;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment