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.Threading.Tasks;
- using System.Windows.Forms;
- using Npgsql;
- namespace Login
- {
- public partial class FormLogIn : Form
- {
- NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432; User Id=postgres;Password=Badb0ll3;Database=pagila;");
- string sql;
- public bool loggedIn = false;
- public string userName;
- public FormLogIn()
- {
- InitializeComponent();
- }
- private void buttonLogIn_Click(object sender, EventArgs e)
- {
- try
- {
- sql = "SELECT * FROM \"user\" WHERE \"user_name\" = '" + textBox1.Text + "' AND password = '" + textBox2.Text + "'";
- //sql = "SELECT * FROM actor WHERE actor_id = 3";
- conn.Open();
- NpgsqlCommand command = new NpgsqlCommand(sql, conn);
- NpgsqlDataReader dr = command.ExecuteReader();
- while (dr.Read())
- {
- //if (textBox1.Text == dr["user_name"].ToString() & textBox2.Text == dr["password"].ToString())
- //{
- MessageBox.Show("Login succcessful");
- loggedIn = true;
- userName = textBox1.Text;
- //}
- //else if (textBox1.Text == dr["user_name"].ToString() & textBox2.Text != dr["password"].ToString())
- //{
- // MessageBox.Show("Rätt användarnamn, men fel lösenord");
- //}
- //else if (textBox1.Text != dr["user_name"].ToString() & textBox2.Text == dr["password"].ToString())
- //{
- // MessageBox.Show("Fel användarnamn, men rätt lösenord");
- //}
- ////if(User.user_name && User.password == User.user_id)
- }
- if (!loggedIn)
- {
- MessageBox.Show("Wrong username or password");
- }
- else
- this.Close();
- conn.Close();
- }
- catch (NpgsqlException ex)
- {
- MessageBox.Show(ex.Message + " funkis ej");
- conn.Close();
- }
- //this.Close();
- }
- private void FormLogIn_FormClosing(object sender, FormClosingEventArgs e)
- {
- loggedIn = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement