How can I check if a user has written his username and password correctly?
- by Sergio Tapia
I'm using a Linq-to-SQL class called Scans.dbml.
In that class I've dragged a table called Users (username, password, role) onto the graphic area and now I can access User object via a UserRepository class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Scanner.Classes
{
public class UserRepository
{
private ScansDataContext db = new ScansDataContext();
public User getUser(string username)
{
return db.Users.SingleOrDefault(x => x.username == username);
}
public bool exists(string username)
{
}
}
}
Now in my Login form, I want to use this Linq-to-SQL goodness to do all the data related activities.
UserRepository users = new UserRepository();
private void btnLogin_Click(object sender, EventArgs e)
{
loginToSystem();
}
private void loginToSystem()
{
if (users.getUser(txtUsername.Text))
{
}
//If txtUsername exists && User.password == Salt(txtPassword)
//then Show.MainForm() with User.accountType in constructor to set permissions.
}
I need help with verifying that a user exists && that that users.password is equal to SALT(txtpassword.text).
Any guidance please?