How can I check if a user has written his username and password correctly?

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-06-17T14:59:53Z Indexed on 2010/06/17 15:03 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

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.
    }
  1. I need help with verifying that a user exists && that that users.password is equal to SALT(txtpassword.text).

Any guidance please?

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql