public static void saveUser(UserStruct UserDetails) { SQLiteCommand command = new SQLiteCommand(); try { DAL.OpenConnect(); command = new SQLiteCommand(null, DAL.connection); command.CommandText = "INSERT INTO Users(UserName, Password) " + " VALUES (@User_UserName, @User_Password)"; SQLiteParameter UserName = new SQLiteParameter("@User_UserName", UserDetails.getUserName()); SQLiteParameter Password = new SQLiteParameter("@User_Password", UserDetails.getPassword()); command.Parameters.Add(UserName); command.Parameters.Add(Password); command.Prepare(); int changes = command.ExecuteNonQuery(); command.Dispose(); DAL.CloseConnect(); Logger.Log.Info("The registrtion of " + UserDetails.getUserName() + " is Succeeded"); } catch (SQLiteException e) { Logger.Log.Fatal("while the saving process of " + UserDetails.getUserName() + " accord, there was an error -" + e.Message); command.Dispose(); DAL.CloseConnect(); } }
public static UserStruct?isPasswordExist(String Email, String Password) { UserStruct tempUser = new UserStruct(); String[] arr = Email.Split('@'); String username = arr[0]; for (int i = 0; i < users.Count; i++) { tempUser = users[i]; if (tempUser.getUserName().Equals(username)) { String tempPass = tempUser.getUser()[username].ToString(); if (tempPass.Equals(Password)) { return(tempUser); } } } return(null); /* * if (!File.Exists(UsersFile)) // file exist check * { * File.Create(UsersFile); * } * * Stream stream = File.OpenRead(UsersFile); * BinaryFormatter formatter = new BinaryFormatter(); * stream.Position = 0; * try * { * while (stream.Position < stream.Length) * { // pass on the data in the file * UserStruct UserDetails = (UserStruct)formatter.Deserialize(stream); * String passtry = UserDetails.getUser()[Email].ToString(); * if (passtry.Equals(Password)) * { // check if the password match to the email * stream.Close(); * return UserDetails; * } * } * } * catch (Exception e) * { * MileStone4.DataAcces_Layer.Logger.Log.Fatal("while check if email "+Email+" and password "+Password+" match, an error accord - "+e.Message); * } * stream.Close(); * return null; */ }
public static Boolean isEmailExist(String Email) { //Hashtable tempHash = new Hashtable(); //tempHash[Email] String[] arr = Email.Split('@'); String username = arr[0]; UserStruct tempUser = new UserStruct(); for (int i = 0; i < users.Count; i++) { tempUser = users[i]; if (tempUser.getUserName().Equals(username)) { return(true); } } return(false); /* * if (!File.Exists(UsersFile)) // exist file check * { * Stream s = File.Create(UsersFile); * s.Close(); * } * * Stream stream = File.OpenRead(UsersFile); * BinaryFormatter formatter = new BinaryFormatter(); * Email = Email.Split('@')[0]; // Change to user name * stream.Position = 0; * try * { * while (stream.Position < stream.Length) * { // pass on all the data in te file * UserStruct UserDetails = (UserStruct)formatter.Deserialize(stream); * if (UserDetails.getUser().ContainsKey(Email)) // and check if the email is there * { * stream.Close(); * return true; * } * } * stream.Close(); * return false; * } * catch (Exception e) * { * MileStone4.DataAcces_Layer.Logger.Log.Fatal("while check the if the email "+Email+" exist, an error accord - "+e.Message); * return false; * } */ }
public static void saveUser(UserStruct UserDetails) { try { if (!File.Exists(UsersFile)) // exist file check { File.Create(UsersFile); } // open file, and save the user there Stream stream = File.OpenWrite(UsersFile); stream.Position = stream.Length; BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, UserDetails); Console.WriteLine("The registrtion of " + UserDetails.getUserName() + " is Succeeded"); stream.Close(); users.Add(UserDetails); } catch (Exception e) { MileStone4.DataAcces_Layer.Logger.Log.Fatal("while the saving process of " + UserDetails.getUserName() + " accord, there was an error -" + e.Message); } }
public static void load() { //File.Delete(UsersFile); if (!File.Exists(UsersFile)) // file exist check { Stream s = File.Create(UsersFile); s.Close(); } try { Stream stream = File.OpenRead(UsersFile); BinaryFormatter formatter = new BinaryFormatter(); stream.Position = 0; while (stream.Position < stream.Length) { // load all the data to RAM UserStruct currentUser = (UserStruct)formatter.Deserialize(stream); users.Add(currentUser); } stream.Close(); } catch (Exception e) { MileStone4.DataAcces_Layer.Logger.Log.Fatal("error accord while load the DB - " + e.Message); } /* * Console.WriteLine(" ~ Welcome to Kanban! ~"); * while (true) * { * Console.WriteLine("What do you want to do?"); * String todo = Console.ReadLine(); * switch (todo) // action for the user * { * case ("registration"): * User user = new User(); * Console.WriteLine("Please fill the fields below"); * * Console.Write("Email: "); * String email = Console.ReadLine(); * while (!CheckEmailValid(email)) * { // check email * Console.Write("The Email is incorrect, pls enter anouther one: "); * email = Console.ReadLine(); * } * user.Registration(email, "wedontcheckpasswordnow"); // check if the email is can be registration * * Console.Write("Password: "******"The password is incorrect, pls enter anouther one: "); * password = Console.ReadLine(); * } * * if (user.Registration(email, password)) // registration * Console.WriteLine("The registration complete :) "); * Logger.Log.Info("The user "+ email + " is now registry"); // log the event * break; * case ("login"): * User userLogin = new User(); * Console.WriteLine(" ~ Kanbon ~"); * Console.Write("Email: "); // enter the * String emailLogin = Console.ReadLine(); * Console.Write("Password: "******"You in the Kanban!"); * break; * } * * } */ }