public EntHashtable BuscarPasswordSingUp(string hashcode) { SqlCommand cmd = null; EntHashtable hashtable = null; try { SqlConnection connection = Conexion.Instancia.Conectar(); cmd = new SqlCommand("SP_BuscarPasswordSignUp", connection) { CommandType = System.Data.CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@prmstrHashCode", hashcode); connection.Open(); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { hashtable = new EntHashtable { HashCode = Convert.ToString(dataReader["HashCode"]) }; } } catch (SqlException e) { throw e; } finally { cmd.Connection.Close(); } return(hashtable); }
//New password public bool NewHash(EntHashtable hashtable) { SqlCommand cmd = null; bool create; try { SqlConnection connection = Conexion.Instancia.Conectar(); cmd = new SqlCommand("SP_NewHash", connection) { CommandType = System.Data.CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@prmstrHashCode", hashtable.HashCode); connection.Open(); int result = cmd.ExecuteNonQuery(); create = result > 0 ? true : false; } catch (SqlException err) { throw err; } finally { cmd.Connection.Close(); } return(create); }
public bool NewHash(EntHashtable hashtable) { try { return(DatHashtable.Instance.NewHash(hashtable)); } catch (Exception e) { throw e; } }
public List <EntHashtable> BuscarPasswordSingUp() { SqlCommand cmd = null; List <EntHashtable> lista = new List <EntHashtable>(); try { SqlConnection connection = Conexion.Instance.Conectar(); cmd = new SqlCommand("SP_BuscarPasswordSignUp", connection) { CommandType = System.Data.CommandType.StoredProcedure }; connection.Open(); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { EntHashtable hashtable = new EntHashtable { HashCode = Convert.ToString(dataReader["HashCode"]) }; lista.Add(hashtable); } } catch (SqlException e) { throw e; } finally { cmd.Connection.Close(); } return(lista); }
//[HttpGet] //public ActionResult NuevaCuenta(int ClienteID) //{ // ViewBag.ClienteID = ClienteID; // return View(ClienteID); //} //[HttpPost] //public ActionResult NuevaCuenta(FormCollection form) //{ // try // { // EntCliente cliente = new EntCliente // { // ClienteID = Convert.ToInt32(form["clienteID"]) // }; // EntAccount cuenta = new EntAccount // { // Cliente = cliente, // Email = Convert.ToString(form["email"]), // Fechacreacion = DateTime.Now.ToString("MM/dd/yyyy"), // NombreUsuario = Convert.ToString(form["username"]), // Telefono = Convert.ToString(form["telf"]) // }; // if (!ModelState.IsValid) // { // return View("NuevaCuenta", cliente); // } // bool nuevaCuenta = LogAccount.Instance.CrearCuenta(cuenta); // if (nuevaCuenta) // { // return RedirectToAction("Index", "Home"); // } // else // { // return View("NuevaCuenta", cuenta); // } // } // catch (Exception ex) // { // return RedirectToAction("NuevaCuenta", new { mesjException = ex.Message }); // } //} public JsonResult NewAccount(EntAccountViewData accountViewData) { //Crea cuenta primero bool cuentaCreada = LogAccount.Instance.CrearCuenta(accountViewData.account); //Encrypt Password string hashcode = ""; string password = accountViewData.PasswordAccount.PasswordString; if (cuentaCreada) { EntPasswordAccount passwordAccount = new EntPasswordAccount { PasswordString = accountViewData.PasswordAccount.PasswordString }; //Verificamos si existe una contraseña de la lista hash List <EntHashtable> lista = LogHashtable.Instance.BuscarPasswordSingUp(); bool existe = false; if (lista.Count > 0) { foreach (var hash in lista) { if (LogHashing.Instance.Comparar(password, hash.HashCode)) { hashcode = hash.HashCode; existe = true; } } } if (existe) { EntHashtable hashtable = new EntHashtable { HashCode = hashcode }; EntAccountHashTable accountHashTable = new EntAccountHashTable { Cuenta = accountViewData.account, Hashtable = hashtable }; //Si se encontró enlaza la cuenta con la contraseña if (LogAccountHashTable.Instance.EnlazarHashCuenta(accountHashTable)) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); } else { hashcode = LogHashing.Instance.Encrypt(password); EntHashtable hashtable = new EntHashtable { HashCode = hashcode }; //Si la contraseña es nueva, crea un nuevo hash bool hashtableCreate = LogHashtable.Instance.NewHash(hashtable); if (hashtableCreate) { passwordAccount.Hashtable = hashtable; //Crea una nueva contraseña bool newPassCreated = LogPasswordAccount.Instance.NewPassword(passwordAccount); if (newPassCreated) { EntAccountHashTable accountHashTable = new EntAccountHashTable { Cuenta = accountViewData.account, Hashtable = hashtable }; //Enlaza la nueva contraseña if (LogAccountHashTable.Instance.EnlazarHashCuenta(accountHashTable)) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); } else { return(Json(false, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }
//[HttpGet] //public ActionResult NuevaCuenta(int ClienteID) //{ // ViewBag.ClienteID = ClienteID; // return View(ClienteID); //} //[HttpPost] //public ActionResult NuevaCuenta(FormCollection form) //{ // try // { // EntCliente cliente = new EntCliente // { // ClienteID = Convert.ToInt32(form["clienteID"]) // }; // EntAccount cuenta = new EntAccount // { // Cliente = cliente, // Email = Convert.ToString(form["email"]), // Fechacreacion = DateTime.Now.ToString("MM/dd/yyyy"), // NombreUsuario = Convert.ToString(form["username"]), // Telefono = Convert.ToString(form["telf"]) // }; // if (!ModelState.IsValid) // { // return View("NuevaCuenta", cliente); // } // bool nuevaCuenta = LogAccount.Instance.CrearCuenta(cuenta); // if (nuevaCuenta) // { // return RedirectToAction("Index", "Home"); // } // else // { // return View("NuevaCuenta", cuenta); // } // } // catch (Exception ex) // { // return RedirectToAction("NuevaCuenta", new { mesjException = ex.Message }); // } //} public JsonResult NewAccount(EntAccountViewData accountViewData) { //Crea cuenta primero bool cuentaCreada = LogCuenta.Instancia.CrearCuenta(accountViewData.Cuenta); //Encrypt Password string hashcode = LogHashing.Instance.Encrypt(accountViewData.Key); //string password = accountViewData.PasswordAccount.PasswordString; if (cuentaCreada) { EntPasswordAccount passwordAccount = new EntPasswordAccount { PasswordString = LogHashing.Instance.Decrypt(accountViewData.Key) }; //Verificamos si existe una contraseña de la lista hash bool existe = false; EntHashtable hashtable = LogHashtable.Instance.BuscarPasswordSingUp(hashcode); if (hashtable != null) { existe = true; } if (existe) { EntAccountHashTable accountHashTable = new EntAccountHashTable { Cuenta = accountViewData.Cuenta, Hashtable = hashtable }; //Si se encontró enlaza la cuenta con la contraseña if (LogAccountHashTable.Instance.EnlazarHashCuenta(accountHashTable)) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); } else { hashtable = new EntHashtable { HashCode = hashcode }; //Si la contraseña es nueva, crea un nuevo hash bool hashtableCreate = LogHashtable.Instance.NewHash(hashtable); if (hashtableCreate) { passwordAccount.Hashtable = hashtable; //Crea una nueva contraseña bool newPassCreated = LogPasswordAccount.Instance.NewPassword(passwordAccount); if (newPassCreated) { EntAccountHashTable accountHashTable = new EntAccountHashTable { Cuenta = accountViewData.Cuenta, Hashtable = hashtable }; //Enlaza la nueva contraseña if (LogAccountHashTable.Instance.EnlazarHashCuenta(accountHashTable)) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); } else { return(Json(false, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); } } return(Json(false, JsonRequestBehavior.AllowGet)); }