Пример #1
0
        public ActionResult CreateUser(WebPlastic.Models.User model)
        {
            ConnectionDataBase.StoreProcediur data = new ConnectionDataBase.StoreProcediur();
            CredencialesDeAcceso access            = new CredencialesDeAcceso();
            string          password   = access.CreatePassword();
            RijndaelManaged myRijndael = new RijndaelManaged();

            myRijndael.GenerateKey();
            myRijndael.GenerateIV();
            string user = access.CreateUserName(model.Name, model.Last).ToLower();

            model.UserName = user;
            Byte[] contrasenaEncriptada = access.EncryptStringToBytes(password, myRijndael.Key, myRijndael.IV);

            DataTable dt  = data.SaveUser(model, contrasenaEncriptada, myRijndael.Key, myRijndael.IV);
            DataRow   row = dt.Rows[0];

            if (dt.Rows.Count > 0)
            {
                SentEmail correoCreacion = new SentEmail();
                string    bodyCorreo     = correoCreacion.EmailForNewUser(model.Name, model.Last, model.UserName, password);
                correoCreacion.SendEmailForNewUser(model.Email, "Creación de Usuario", "*****@*****.**", bodyCorreo, "*****@*****.**", "*****@*****.**", "hola1234", "");
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult Login(Models.Login model)
        {
            Session["idUser"]    = null;
            Session["idProfile"] = null;
            Session["Name"]      = null;

            if (model.UserName != null)
            {
                ConnectionDataBase.StoreProcediur data = new ConnectionDataBase.StoreProcediur();
                CredencialesDeAcceso acceso            = new CredencialesDeAcceso();
                DataTable            dt = data.ValidarIngresoUsuario(model.UserName, GetMACAddress().ToString());
                if (dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];

                    byte[] password = (byte[])row["Password"];
                    byte[] key      = (byte[])row["pKEY"];
                    byte[] iv       = (byte[])row["pIV"];
                    if (password.Length > 2)
                    {
                        string finalpassword = acceso.DecryptStringFromBytes(password, key, iv);
                        if (finalpassword == model.Password)
                        {
                            dynamic dol = null;
                            if (dt.Rows.Count == 1)
                            {
                                dol = dt.Rows[0];
                            }
                            else
                            {
                                dol = dt.Rows[1];
                            }
                            Session["idUser"]    = row["idUser"].ToString();
                            Session["idProfile"] = row["idProfile"].ToString();
                            Session["Name"]      = row["Name"].ToString();
                            Session["Last"]      = row["Last"].ToString();
                            Session["Email"]     = row["Email"].ToString();
                            Session["Profile"]   = row["Profile"].ToString();

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            Session["message"] = "Las credenciales de usuario no coinciden, verifique.";
                        }
                    }
                }
                else
                {
                    Session["message"] = "No se encontro datos de usuario con esas credenciales, por favor cree uno.";
                }
                Session["title"] = "Error";
                Session["type"]  = "error";
            }
            return(RedirectToAction("Index"));
        }