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.Data;
- using System.Data.SQLite;
- using System.Security.Cryptography;
- namespace IEP_Test{
- class Program{
- public static string CalculateMD5Hash(string input)
- {
- // step 1, calculate MD5 hash from input
- MD5 md5 = System.Security.Cryptography.MD5.Create();
- byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
- byte[] hash = md5.ComputeHash(inputBytes);
- // step 2, convert byte array to hex string
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < hash.Length; i++)
- {
- sb.Append(hash[i].ToString("X2"));
- }
- return sb.ToString();
- }
- static bool login(string username, string password) {
- IDbConnection connection = new SQLiteConnection("Data Source=iep_db_users.db;Version=3;");
- //IDbCommand command = new SQLiteCommand("SELECT * FROM Users WHERE Username = @usename AND Password = @password", (SQLiteConnection)connection);
- IDbCommand command = new SQLiteCommand("SELECT COUNT(*) FROM Users WHERE Username = @usename AND Password = @password", (SQLiteConnection)connection);
- IDbDataParameter pUser = command.CreateParameter();
- pUser.Value = username;
- command.Parameters.Add(pUser);
- IDbDataParameter pPass = command.CreateParameter();
- pPass.Value = password;
- command.Parameters.Add(pPass);
- connection.Open();
- //IDataReader reader = command.ExecuteReader();
- int cnt = (int)command.ExecuteScalar(); //kad se vraca count i tako ta sranja
- connection.Close();
- /*
- if (reader.Read())
- {
- Console.WriteLine("User: " + reader[0] + " Username: " + reader[1] + " Password: " + reader[2]);
- return true;
- }
- return false;
- */
- if (cnt != 0)
- return true;
- return false;
- }
- static void Main(string[] args) {
- Console.WriteLine("Username: ");
- string username = Console.ReadLine();
- Console.WriteLine("Password: ");
- string password = Console.ReadLine();
- password = CalculateMD5Hash(password);
- if (login(username, password))
- {
- Console.WriteLine("HotDog");
- }
- else {
- Console.WriteLine("Not HotDog");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement