If you are using a windows application, create the login form with two textboxes and two labels for the username and password. Set the UseSystemPassword property to true. Then, create the sql database with at least a table with a username and a password column. Here is a sample code: Please note that DataHelper is my class for connecting to the SQL database in just two lines and LoginInfo is a class for encapsulating the user, his roles and rights. If you want just the user and password, ignore the rest of the code.
private LoginInfo Login()
{
LoginInfo result = new LoginInfo();
try
{
DataHelperMS dh = new DataHelperMS();
String sql = String.Format(@"SELECT user_id, user_name
FROM Users
WHERE (user_id = '{0}' AND user_password = '{1}')", txtUsername.Text.Replace("'", ""), txtPassword.Text.Replace("'", ""));
DataTable userTable = dh.ExecuteDataSet(sql).Tables[0];
result.User_id = userTable.Rows[0][0].ToString();
result.User_name = userTable.Rows[0][1].ToString();
String sql2 = String.Format(@"SELECT R.role_id, R.role_name
FROM Roles R INNER JOIN UserRoles UR ON R.role_id = UR.ur_role_id
WHERE (UR.ur_user_id = '{0}')", result.User_id);
DataTable roleTable = dh.ExecuteDataSet(sql2).Tables[0];
foreach (DataRow row in roleTable.Rows)
{
result.Roles_ids.Add(row[0].ToString());
result.Roles_names.Add(row[1].ToString());
}
foreach (String id in result.Roles_ids)
{
String sql3 = String.Format(@"SELECT R.right_id, R.right_name
FROM Rights R INNER JOIN RoleRights RR ON R.right_id = RR.rr_right_id
WHERE (RR.rr_role_id = '{0}')", id);
DataTable rightTable = dh.ExecuteDataSet(sql3).Tables[0];
foreach (DataRow row in rightTable.Rows)
{
result.Rights_ids.Add(row[0].ToString());
result.Rights_names.Add(row[1].ToString());
}
}
}
catch (Exception)
{
result = null;
}
return result;
}