Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using System.Data.Sql;
- namespace Database
- {
- public partial class Form1 : Form
- {
- private SqlConnection connection = new SqlConnection();
- byte counter = 4;
- byte count = 0;
- string user = null;
- string cString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=\"c:\\users\\user\\documents\\visual studio 2010\\Projects\\Database\\Database\\nbiCCMdb.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True";
- public Form1()
- {
- InitializeComponent();
- connection.ConnectionString = cString;
- }
- private void button2_Click(object sender, EventArgs e)
- {
- connection.Close();
- Application.Exit();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- connection.Open();
- SqlCommand command = new SqlCommand();
- command.Connection = connection;
- command.CommandText = "SELECT * FROM userTable WHERE userName = '" + textBox1.Text + "' AND userPass = '" + textBox2.Text + "'";
- SqlDataReader reader = command.ExecuteReader();
- textBox1.Select();
- while (reader.Read())
- {
- count++;
- }
- if (count == 1)
- {
- user = textBox1.Text;
- textBox1.Clear();
- textBox2.Clear();
- connection.Close();
- this.Hide();
- }
- else if (count != 1 && !(textBox1.Text == String.Empty || textBox2.Text == String.Empty))
- {
- counter--;
- if (counter != 0)
- {
- MessageBox.Show("Incorrect Username/Password please try again." + Environment.NewLine +
- "You have " + counter + " tries left.");
- textBox2.Clear();
- textBox2.Focus();
- }
- }
- else
- {
- MessageBox.Show("Please enter Username/Password.");
- if (textBox1.Text == String.Empty)
- {
- textBox1.Focus();
- }
- else
- {
- textBox2.Focus();
- }
- }
- if (counter == 0)
- {
- MessageBox.Show("You Have Exceeded The Acceptable Amount Of Trials" + Environment.NewLine +
- "Program Terminated.");
- connection.Close();
- Application.Exit();
- }
- connection.Close();
- }
- catch(Exception ex)
- {
- MessageBox.Show("Error " + ex);
- connection.Close();
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox1.Select();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement