public async Task <IActionResult> CrieUsuarioPadrao()
        {
            if (!VerificaSeUsuarioJaExiste("admin"))
            {
                Usuario usuario;
                var     senha = "123456";
                using (var ctx = new EventosDataContext())
                {
                    usuario = new Usuario
                    {
                        DataCadastro = DateTime.Now.Date,
                        Email        = "*****@*****.**",
                        Nome         = "admin",
                        Senha        = senha,
                        UserName     = "******"
                    };

                    usuario.Senha = EncryptPassword.Encode(usuario.Senha);
                    await ctx.Usuario.AddAsync(usuario);

                    await ctx.SaveChangesAsync();
                }

                return(new JsonResult($"Usuario: {usuario.UserName} Senha: {senha}."));
            }
            else
            {
                return(BadRequest("Já existe Usuário com este nome!"));
            }
        }
示例#2
0
        public void UpdatePassword(string username, string password)
        {
            var user = _db.User.Where(x => x.Username == username).SingleOrDefault();

            user.Password         = EncryptPassword.Encode(password);
            _db.Entry(user).State = EntityState.Modified;
            _db.SaveChanges();
        }
示例#3
0
        public ActionResult Create([Bind(Include = "FirstName, LastName, DoB, Gender, ContactNumber, DepartmentId, AgentId, Password, ConfirmPassword")] Agent agent)
        {
            if (ModelState.IsValid)
            {
                if (!db.Agents.Any(x => x.AgentId == agent.AgentId))
                {
                    //var passkey = encryptPassword.Encode(agent.Password);
                    //agent.Password = passkey;
                    //db.Agents.Add(agent);
                    //db.SaveChanges();

                    var confrmpasskey = encryptPassword.Encode(agent.ConfirmPassword);
                    agent.ConfirmPassword = confrmpasskey;

                    var passkey = encryptPassword.Encode(agent.Password);
                    agent.Password = passkey;

                    db.Agents.Add(agent);

                    try
                    {
                        db.SaveChanges();

                        System.Windows.Forms.MessageBox.Show("New Agent Created Successfully");

                        return(View(agent));
                        //return RedirectToAction("UserHome", "Home");
                    }
                    catch (Exception e)
                    {
                        ViewBag.Message = e.Message;

                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Agent ID already exists");

                    return(View(agent));
                }
            }

            return(View(agent));
        }
        public void Check_Hashed_Password_Length()
        {
            var hashedLength = 40;
            var password     = "******";

            var result = EncryptPassword.Encode(password);

            Assert.AreEqual(hashedLength, result.Length);
        }
示例#5
0
 public ActionResult AgentCreate([Bind(Include = "FirstName,LastName,DoB,Gender,ContactNumber,DepartmentId,AgentId,Password,ConfirmPassword")] Agent agent)
 {
     if (ModelState.IsValid)
     {
         if (!db.Agents.Any(x => x.AgentId == agent.AgentId))
         {
             var passkey = encryptPassword.Encode(agent.A_Password);
             agent.A_Password = passkey;
             db.Agents.Add(agent);
             db.SaveChanges();
             MessageBox.Show("New Agent Created Successfully");
             return(RedirectToAction("AgentHome", "Home"));
         }
         else
         {
             ModelState.AddModelError("", "Agent Name / ID already exists");
             return(View(agent));
         }
     }
     return(View(agent));
 }
        public ActionResult Create([Bind(Include = "FirstName, LastName, DoB, Gender, ContactNumber, Email, UserId, Password, ConfirmPassword, Answer1, Answer2, Answer3")] User user)
        {
            if (ModelState.IsValid)
            {
                if (!db.Users.Any(x => x.UserId == user.UserId))
                {
                    var confrmpasskey = encryptPassword.Encode(user.ConfirmPassword);
                    user.ConfirmPassword = confrmpasskey;

                    var passkey = encryptPassword.Encode(user.Password);
                    user.Password = passkey;

                    db.Users.Add(user);

                    try
                    {
                        db.SaveChanges();

                        MessageBox.Show("New User Created Successfully");

                        return(View(user));
                        //return RedirectToAction("UserHome", "Home");
                    }
                    catch (Exception e)
                    {
                        ViewBag.Message = e.Message;

                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "User ID already exists");

                    return(View(user));
                }
            }

            return(View(user));
        }
        public AuthenticationStatus Login(string username, string password)
        {
            var isAuthenticated = _authenticationService.AuthenticateUser(username, EncryptPassword.Encode(password));

            if (isAuthenticated == AuthenticationStatus.INCORRECT_DETAILS)
            {
                isAuthenticated = HandleFailedLogin(username);
            }
            else if (isAuthenticated == AuthenticationStatus.LOGGED_IN)
            {
                CompleteLogin(username);
                CreateSession(username);
            }

            return(isAuthenticated);
        }
        public async Task <IActionResult> Novo([FromBody] Usuario usuario)
        {
            if (!VerificaSeUsuarioJaExiste(usuario.UserName))
            {
                using (var ctx = new EventosDataContext())
                {
                    usuario.Senha = EncryptPassword.Encode(usuario.Senha);
                    await ctx.Usuario.AddAsync(usuario);

                    await ctx.SaveChangesAsync();
                }

                return(Ok(usuario));
            }
            else
            {
                return(BadRequest("Já existe Usuário com este nome!"));
            }
        }
        public ActionResult Login(Admin adminLogin)
        {
            if (adminLogin.AdminId != null)
            {
                if (adminLogin.Password != null)
                {
                    string password = encryptPassword.Encode(adminLogin.Password);

                    if (db.Admins.Any(b => b.AdminId.Equals(adminLogin.AdminId, StringComparison.InvariantCultureIgnoreCase) && b.Password.Equals(adminLogin.Password, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        FormsAuthentication.SetAuthCookie(adminLogin.AdminId, false);

                        Session["AdminId"] = adminLogin.AdminId;

                        return(RedirectToAction("Index", new { adminLogin.AdminId }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "User Name / Password is Incorrect");

                        return(View());
                    }
                }

                else
                {
                    ModelState.AddModelError("", "Please enter Log In credentials");

                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("", "Please enter Log In credentials");

                return(View());
            }
        }