///<summary> ///Retrieve user from file ///</summary> ///<param name="email">string</param> ///<param name="email">string</param> ///<returns>User class object</returns> ///<remarks> ///</remarks> public User retreiveUser(string email, string password) { User rUser = null; //find user from database DataTableOperations source = new DataTableOperations(Properties.Settings.Default.ConnectionString, Properties.Settings.Default.LoginSQL, "Login"); DataTable t = new DataTable(); t = source.Datatable; foreach (DataRow item in t.Rows) { if (item["email"].ToString().Equals(email)) { if (item["password"].ToString().Equals(User.HashPass(password,email))) { rUser = new User(email, password); } } else { Console.Write("Record not found"); } } return rUser; }
///<summary> ///Create a new user ///</summary> ///<param name="password">string</param> ///<param name="confirmPW">string</param> ///<param name="regEmail">string</param> ///<returns>True if user create successfully</returns> ///<remarks> ///The user data will persist on local file until they are added to database ///</remarks> public static Boolean AddUser(string password, string confirmPW, string regEmail) { Boolean userAdded = false; //Make sure email is valid Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); try { Match match = regex.Match(regEmail); #region Check for existing email ////loop full through logins table //foreach (DataRow row in LoginDataSet.LoginsDataTable()) //{ // //Look for matching email // if (row.ItemArray[0].Equals(email)) // { // Console.WriteLine("email already exists"); // } //} #endregion //Confirm pass must equal passsword. if (password != confirmPW) { Console.WriteLine("Passwords do not match"); } //Password must be at least 8 characters long else if (password.Length < 8) { Console.WriteLine("Passwords must be at 8 Characters long"); } else if (!match.Success) { Console.WriteLine("invalid email"); } //If all is well, create the new user else { User newUser = new User(regEmail, password); user = newUser; userAdded = true; } return userAdded; } finally { SaveUser(); } }