Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Security.Cryptography;
- using MySql.Data.MySqlClient;
- namespace login
- {
- class Program
- {
- static string connString = "SERVER=shadowdriz.lima-db.de;" +
- "DATABASE=db_353486_1;" +
- "UID=USER353486;" +
- "PASSWORD=censored girl dont even look. XD;";
- static void Main(string[] args)
- {
- A:
- Console.Clear();
- string id, pw, answer;
- Console.Write("id:");
- id = Console.ReadLine();
- Console.Write("pw:");
- pw = ReadPassword();
- if (IsValid(id, pw))
- {
- Console.WriteLine("Successfully Logged in!");
- }
- else
- {
- Console.WriteLine("Wrong Credentials!");
- Console.WriteLine("Do you want to sign up? y/n");
- if ((answer = Console.ReadLine()) == "y")
- SignUp();
- else
- goto A;
- }
- }
- static void SignUp()
- {
- Console.Clear();
- Console.Write("id:");
- string id = Console.ReadLine();
- B:
- Console.Write("pw:");
- string pw = ReadPassword();
- Console.Write("pw:");
- string pw2 = ReadPassword();
- if (pw == pw2)
- {
- Console.WriteLine("Signing up..");
- Console.WriteLine("Checking if id is available..");
- }
- else
- {
- Console.WriteLine("Your passwords do not match! Try again!");
- goto B;
- }
- }
- static bool IsValid(string id, string pw)
- {
- using (MySqlConnection conn = new MySqlConnection(connString))
- {
- MySqlCommand cmd = conn.CreateCommand();
- cmd.CommandText = "select password from users where username='@username';";
- conn.Open();
- MySqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- if (reader.HasRows)
- {
- string password = reader.GetString(0);
- if ((pw = GetMD5(pw)) == password)
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- static string GetMD5(string text2hash)
- {
- StringBuilder sb = new StringBuilder();
- using (MD5 md5 = MD5.Create())
- {
- byte[] data = md5.ComputeHash(ASCIIEncoding.UTF8.GetBytes(text2hash));
- for (int i = 0; i < data.Length; i++)
- {
- sb.Append(data[i].ToString("x2"));
- }
- }
- return sb.ToString();
- }
- static string ReadPassword()
- {
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- ConsoleKeyInfo i = Console.ReadKey(true);
- if (i.Key == ConsoleKey.Enter)
- {
- Console.WriteLine();
- break;
- }
- if (i.Key == ConsoleKey.Backspace)
- {
- if (sb.Length > 0)
- {
- Console.Write("\b \b");
- sb.Length--;
- continue;
- }
- }
- Console.Write('*');
- sb.Append(i.KeyChar);
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement