public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public bool ValidateApplicationUser(string userName, string password)
{
bool validUser = false;
try
{
var conn = "Data Source=MAMMA-PC/SQLMAMMA;Initial Catalog=MyWebSite;Integrated Security=True";
DataClasses1DataContext dc = new DataClasses1DataContext(conn);
Table<User> users = dc.GetTable<User>();
var query = from c in dc.Users
where (c.Username == userName.ToLower() && c.Password == password.ToLower())
select c;
validUser = (query != null);
}
catch (Exception ex)
{
if (ex != null)
{
}
}
return validUser;
}
private void mahhh(object sender, RoutedEventArgs e)
{
bool authenticated = true;
var conn = "Data Source=MAMMA-PC/SQLMAMMA;Initial Catalog=MyWebSite;Integrated Security=True";
DataClasses1DataContext dc = new DataClasses1DataContext(conn);
Table<User> users = dc.GetTable<User>();
var query = from c in dc.Users
where (c.Username == usernameTextBox.Text && c.Password == passwordTextBox.Text)
select c;
{
if (usernameTextBox.Text != "" && passwordTextBox.Text != "")
{
authenticated = ValidateApplicationUser(usernameTextBox.Text , passwordTextBox.Text);
}
}
if (!authenticated)
{
MessageBox.Show("Invalid login. Try again.");
}
else
{
MessageBox.Show("Congradulations! You're a valid user!");
Window2 c = new Window2();
c.ShowDialog();
this.Close();
}
}
}
THat's an example of my code but easch time that i will authenticate with a wrong password(different from the database) its doesn't recognise the error and validate each password.
Do you have some idea about that?
Thanks