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 MySql.Data.MySqlClient;
- using System.Text.RegularExpressions;
- namespace SimpliD
- {
- public partial class Form1 : Form
- {
- public void CheckLogin(string uname, string pass)
- {
- bool LoginCheck;
- string MyConString = "SERVER = 192.168.2.183; DATABASE = myDB; User ID = root; PASSWORD = mypassword;";
- MySqlConnection connection = new MySqlConnection(MyConString);
- MySqlCommand command = connection.CreateCommand();
- MySqlDataReader Reader;
- command.CommandText = "select * from users where username='" + uname + "'" ;
- connection.Open();
- Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- string row = "";
- for (int i = 0; i < Reader.FieldCount; i++)
- row += Reader.GetValue(i).ToString() + ":sep:";
- row = Regex.Replace(row, "ä", "ä");
- row = Regex.Replace(row, "ö", "ö");
- row = Regex.Replace(row, "Ã¥", "å");
- string[] List = Regex.Split(row, ":sep:");
- if (uname == List[1] && pass == List[2])
- {
- LoginCheck = true;
- label1.Text = "Inloggad som " + List[1];
- LoginCheckSuccess();
- }
- else if (uname != List[1] || pass != List[2]){ label1.Text = "Inloggningen misslyckades!"; LoginCheck = false; }
- }
- connection.Close();
- }
- public void LoginCheckSuccess()
- {
- LoggedIn LoggedInDialog = new LoggedIn();
- if (LoggedInDialog.ShowDialog(this) == DialogResult.OK)
- {
- }
- else
- {
- }
- LoggedInDialog.Dispose();
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string username = textBox1.Text;
- string password = textBox2.Text;
- CheckLogin(username, password);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox2.PasswordChar = '*';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement