Usually I create a new form something like this.
public partial class LoginForm : Form { public bool letsGO = false; public LoginForm() { InitializeComponent(); textUser.CharacterCasing = CharacterCasing.Upper; } public string UserName { get { return textUser.Text; } } private static DataTable LookupUser(string Username) { const string connStr = "Server=(local);" + "Database=LabelPrinter;" + "trusted_connection= true;" + "integrated security= true;" + "Connect Timeout=1000;";
then in your main form do the following:
public Form1(string userName) {
and then:
static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LoginForm fLogin = new LoginForm(); if (fLogin.ShowDialog() == DialogResult.OK) { Application.Run(new Form1(fLogin.UserName)); } else { Application.Exit(); } //Application.Run(new Form1()); }
I hope this gives a general idea of ββwhat to do, although I am sure that theirs is a much better way to do this, also note that this is not a very secure interface.
Hope this helps:
EDIT: oh and before i forget don't use
Select password From dbo.UserTable (NOLOCK) Where UserName = @UserName
I will just throw it in a stored procedure. But in any case, this is not the best authentication method, but its working solution, at least you will go. I hope that
source share