Advertisement
Guest User

FormLogIn

a guest
Aug 28th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Npgsql;
  11.  
  12. namespace Login
  13. {
  14.     public partial class FormLogIn : Form
  15.     {
  16.  
  17.         NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432; User Id=postgres;Password=Badb0ll3;Database=pagila;");
  18.  
  19.         string sql;
  20.         public bool loggedIn = false;
  21.         public string userName;
  22.  
  23.         public FormLogIn()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.  
  28.         private void buttonLogIn_Click(object sender, EventArgs e)
  29.         {
  30.             try
  31.             {
  32.                 sql = "SELECT * FROM \"user\" WHERE \"user_name\" = '" + textBox1.Text + "' AND password = '" + textBox2.Text + "'";
  33.                 //sql = "SELECT * FROM actor WHERE actor_id = 3";
  34.                 conn.Open();
  35.                 NpgsqlCommand command = new NpgsqlCommand(sql, conn);
  36.                 NpgsqlDataReader dr = command.ExecuteReader();
  37.  
  38.                 while (dr.Read())
  39.                 {
  40.                     //if (textBox1.Text == dr["user_name"].ToString() & textBox2.Text == dr["password"].ToString())
  41.                     //{
  42.                         MessageBox.Show("Login succcessful");
  43.                         loggedIn = true;
  44.                         userName = textBox1.Text;
  45.                        
  46.                     //}
  47.                     //else if (textBox1.Text == dr["user_name"].ToString() & textBox2.Text != dr["password"].ToString())
  48.                     //{
  49.                     //    MessageBox.Show("Rätt användarnamn, men fel lösenord");
  50.                     //}
  51.                     //else if (textBox1.Text != dr["user_name"].ToString() & textBox2.Text == dr["password"].ToString())
  52.                     //{
  53.                     //    MessageBox.Show("Fel användarnamn, men rätt lösenord");
  54.                     //}
  55.                     ////if(User.user_name && User.password == User.user_id)
  56.                 }
  57.  
  58.                 if (!loggedIn)
  59.                 {
  60.                     MessageBox.Show("Wrong username or password");
  61.                 }
  62.                 else
  63.                     this.Close();
  64.  
  65.  
  66.                 conn.Close();
  67.             }
  68.  
  69.             catch (NpgsqlException ex)
  70.             {
  71.                 MessageBox.Show(ex.Message + " funkis ej");
  72.                 conn.Close();
  73.             }
  74.  
  75.             //this.Close();
  76.         }
  77.  
  78.         private void FormLogIn_FormClosing(object sender, FormClosingEventArgs e)
  79.         {
  80.             loggedIn = false;
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement