private void verifylogin() { string password = Encryptordecrypt.Decript_String(txtpass.Text); sqlconnectionclass read4login = new sqlconnectionclass(); DR = read4login.ReadDB("select [user_id],[username],[password],[userlevel],[status] from [users] where username COLLATE Latin1_General_CS_AS='" + txtusername.Text + "' and [password] COLLATE Latin1_General_CS_AS='" + password + "'"); if (DR.HasRows) { sqlconnectionclass checkstatus = new sqlconnectionclass(); DR1 = checkstatus.ReadDB("select [user_id],[username],[password],[userlevel],[status] from [users] where username COLLATE Latin1_General_CS_AS='" + txtusername.Text + "' and [password] COLLATE Latin1_General_CS_AS='" + password + "'and status = 'active'"); if (DR1.HasRows) { while (DR.Read()) { this.DialogResult = DialogResult.OK; //usernamemenu.FindForm(Menu).Text = DR["username"].ToString(); userid = DR["user_id"].ToString(); UserName = DR["username"].ToString(); userlevel = DR["userlevel"].ToString(); string user = "******" + Form1.UserName; //string insert = "insert into usersession(user_id,logintime,logouttime)values('" + Form1.userid + "','" + System.DateTime.Now + "','" + System.DateTime.Now + "')"; //new sqlconnectionclass().WriteDB(insert); foreach (Form f in Application.OpenForms) { f.Text = user; } } } else { MessageBox.Show("User account" + txtusername.Text + " is deactivated \n Contact the administrator"); Application.Exit(); } } else if (attempts >= 3) { MessageBox.Show("Maximum number of attempts" + "\r\n the user account is deactivated!", "Attempts Exceeded", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Exit(); } else { sqlconnectionclass checkuserexist = new sqlconnectionclass(); DR2 = checkuserexist.ReadDB("select user_id,username,password from users where username COLLATE Latin1_General_CS_AS='" + txtusername.Text + "'"); if (DR.HasRows) { MessageBox.Show("Username and password incorrect, Please try again \r\n Current attempts:" + string.Concat(attempts, " of 3"), "Attempts space", MessageBoxButtons.OK, MessageBoxIcon.Error); attempts += 1; //txtusername.Text = ""; txtpass.Text = ""; } else { MessageBox.Show("Username" + txtusername.Text + " doesn't exist"); } } }
static void Main() { System.Data.SqlClient.SqlDataReader DR; //Application.Run(new Sales()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); sqlconnectionclass read4login = new sqlconnectionclass(); DR = read4login.ReadDB("select * from [users]"); if (DR.HasRows) { while (DR.Read()) { Form1 L = new Form1(); DialogResult dr = L.ShowDialog(); if (dr == DialogResult.OK) { Home F = new Home(); F.Text = "EasyPOS" + " " + "You are login as: " + Form1.UserName; Application.Run(F); } } } else { try { string datet = System.DateTime.Now.ToString(); string password = Encryptordecrypt.Decript_String("admin123");// Decryptor.Decript_String(textBox1.Text); string username = "******"; string userlevel = "super_admin"; string inserttousers = ("INSERT INTO users(username,password,userlevel,created_at)values('" + username + "','" + password + "','" + userlevel + "','" + datet + "')"); new sqlconnectionclass().WriteDB(inserttousers); } catch (Exception) { } finally { Form1 L = new Form1(); DialogResult dr = L.ShowDialog(); if (dr == DialogResult.OK) { Home F = new Home(); F.Text = "EasyPOS" + "" + "You are login as: " + Form1.UserName; Application.Run(F); } } } }
private void btnadd_Click(object sender, EventArgs e) { if (txtpassword.TextLength > 0 && txtusername.TextLength > 0) { String datet = System.DateTime.Now.ToString(); if (btnadd.Text == "Add User") { string password = Encryptordecrypt.Decript_String(txtpassword.Text);// Decryptor.Decript_String(textBox1.Text); string username = txtusername.Text; string userlevel = comboBox1.Text; string inserttousers = ("INSERT INTO users(username,password,userlevel,created_at)values('" + username + "','" + password + "','" + userlevel + "','" + datet + "')"); new sqlconnectionclass().WriteDB(inserttousers); MessageBox.Show("User added successfully!"); txtpassword.Text = ""; txtusername.Text = ""; comboBox1.Text = "Select User Level"; Bindgridview(); } else if (btnadd.Text == "Update") { string password = Encryptordecrypt.Decript_String(txtpassword.Text);// Decryptor.Decript_String(textBox1.Text); string username = txtusername.Text; string userlevel = comboBox1.Text; string Updateusers = ("UPDATE users SET username='******',password='******',userlevel='" + userlevel + "',created_at='" + datet + "' where user_id='" + label1.Text + "'"); new sqlconnectionclass().WriteDB(Updateusers); MessageBox.Show("User Updated successfully!"); txtpassword.Text = ""; txtusername.Text = ""; comboBox1.Text = "Select User Level"; Bindgridview(); } } else { MessageBox.Show("Username and password cannot be empty!"); } }