Advertisement
Guest User

Untitled

a guest
May 7th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 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.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10. using System.Text.RegularExpressions;
  11.  
  12.  
  13. namespace SimpliD
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.  
  18.         public void CheckLogin(string uname, string pass)
  19.         {
  20.             bool LoginCheck;
  21.             string MyConString = "SERVER = 192.168.2.183; DATABASE = myDB; User ID = root; PASSWORD = mypassword;";
  22.  
  23.             MySqlConnection connection = new MySqlConnection(MyConString);
  24.             MySqlCommand command = connection.CreateCommand();
  25.             MySqlDataReader Reader;
  26.             command.CommandText = "select * from users where username='" + uname + "'" ;
  27.             connection.Open();
  28.             Reader = command.ExecuteReader();
  29.  
  30.             while (Reader.Read())
  31.             {
  32.                 string row = "";
  33.                 for (int i = 0; i < Reader.FieldCount; i++)
  34.                     row += Reader.GetValue(i).ToString() + ":sep:";
  35.                 row = Regex.Replace(row, "ä", "ä");
  36.                 row = Regex.Replace(row, "ö", "ö");
  37.                 row = Regex.Replace(row, "Ã¥", "å");
  38.                 string[] List = Regex.Split(row, ":sep:");
  39.  
  40.                 if (uname == List[1] && pass == List[2])
  41.                 {
  42.                     LoginCheck = true;
  43.                     label1.Text = "Inloggad som " + List[1];
  44.                     LoginCheckSuccess();
  45.                 }
  46.                 else if (uname != List[1] || pass != List[2]){ label1.Text = "Inloggningen misslyckades!"; LoginCheck = false; }
  47.             }
  48.             connection.Close();
  49.  
  50.         }
  51.  
  52.  
  53.         public void LoginCheckSuccess()
  54.         {
  55.             LoggedIn LoggedInDialog = new LoggedIn();
  56.  
  57.  
  58.             if (LoggedInDialog.ShowDialog(this) == DialogResult.OK)
  59.             {
  60.  
  61.             }
  62.             else
  63.             {
  64.  
  65.             }
  66.             LoggedInDialog.Dispose();
  67.         }
  68.  
  69.         public Form1()
  70.         {
  71.  
  72.             InitializeComponent();
  73.         }        
  74.        
  75.  
  76.         private void button1_Click(object sender, EventArgs e)
  77.         {
  78.            
  79.             string username = textBox1.Text;
  80.             string password = textBox2.Text;
  81.             CheckLogin(username, password);
  82.            
  83.         }
  84.  
  85.         private void Form1_Load(object sender, EventArgs e)
  86.         {
  87.             textBox2.PasswordChar = '*';
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement