예제 #1
0
        public static User ExistingUserLogIn(string username)
        {
            Console.WriteLine("Existing user login.");
            bool   validLogin;
            string password = "";
            User   user     = new User();

            do
            {
                try
                {
                    Console.WriteLine("Password: "******"Invalid password. Please try again.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    validLogin = false;
                }
            }while (validLogin == false);
            return(user);
        }
예제 #2
0
        public bool ValidatePasswordAgainstHash(string password, string salt, string knownHash)
        {
            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(salt))
            {
                return(false);
            }

            var passwordHash = _cryptoService.Compute(password, salt);

            return(_cryptoService.Compare(passwordHash, knownHash));
        }
예제 #3
0
        public void Login(string email, string pass, int perfil)
        {
            var list = bd.usuarios.Where(x => x.email == email && x.idperfil == perfil).FirstOrDefault();

            if (list != null)
            {
                passEncryptada = cryptoService.Compute(pass, list.salt);
                if (cryptoService.Compare(list.pass, passEncryptada))
                {
                    var lista = (from us in bd.usuarios
                                 join pe in bd.personas on us.idpersona equals pe.id
                                 where us.id == list.id
                                 select new
                    {
                        id = us.id,
                        idperfil = us.idperfil,
                        idpersona = us.idpersona,
                        nombre = pe.nombre,
                        apellido = pe.apellido,
                        telefono = pe.telefono,
                        sexo = pe.sexo,
                        curp = pe.curp,
                        fechanacimiento = pe.fechanacimiento,
                        longi = pe.@long,
                        lat = pe.lat,
                        idinteres = pe.idinteres,
                        fotoperfil = pe.fotoperfil
                    }).ToList();
                    json = JsonConvert.SerializeObject(lista);
                }
                else
                {
                    json = JsonConvert.SerializeObject("[{ mensaje : '1' }]"); //La contraseña es incorrecta
                }
            }
            else
            {
                json = JsonConvert.SerializeObject("[{mensaje : '0'}]");// el usuario no existe u el perfil es incorrecto
            }
            con.Response.Write(json);
            con.Response.End();
        }
예제 #4
0
        public async Task LoginAsync(string email, string password)
        {
            var user = await _userRepository.GetByEmailAsync(email);

            if (user == null)
            {
                throw new OcenUczelnieException(ErrorCodes.InvalidCredentials);
            }
            var generatedHash = _cryptoService.Compute(password, user.Salt);

            if (!_cryptoService.Compare(generatedHash, user.Password))
            {
                throw new OcenUczelnieException(ErrorCodes.InvalidCredentials);
            }
            if (!user.IsConfirmed)
            {
                throw new OcenUczelnieException(ErrorCodes.NotActivated,
                                                "User is not activated.");
            }
            var token = _tokenProvider.CreateToken(user.Id, user.Role);

            _memoryCache.Set("generatedToken", token, TimeSpan.FromSeconds(5));
        }
예제 #5
0
        public IActionResult EditPassword(string username, [FromForm] UserEditPasswordRequest editRequest)
        {
            var userId = AuthController.GetUserIdFromPrincipal(Request, config.Secret);

            var user = authUnit.Users.GetUserById(userId);

            // Validate user
            if (user == null)
            {
                return(NotFound());
            }

            if (user.Username != username)
            {
                return(Unauthorized());
            }

            // Compare existing password
            var oldHash = cryptoService.Compute(editRequest.OldPassword, user.PasswordSalt);

            if (!cryptoService.Compare(user.Password, oldHash))
            {
                return(BadRequest());
            }

            // Set new password
            var newHash = cryptoService.Compute(editRequest.NewPassword);

            user.Password     = newHash;
            user.PasswordSalt = cryptoService.Salt;

            authUnit.Users.UpdateUser(user);
            authUnit.Complete();

            return(NoContent());
        }
        public bool CheckPbkdf2Format(PasswordModel model)
        {
            var hashedPassword = _cryptoService.Compute(model.Password, model.SaltKey);

            return(_cryptoService.Compare(hashedPassword, model.HashedPassword));
        }
예제 #7
0
 public bool Compare(string hashedPassword1, string hashedPassword2)
 {
     return(_simpleCrypto.Compare(hashedPassword1, hashedPassword2));
 }
예제 #8
0
 public bool Compare(string passwordHash1, string passwordHash2)
 {
     return(_simpleCrypto.Compare(passwordHash1, passwordHash2));
 }