public int RegistrarUsuario(String username, String password, String pregunta, String respuesta)
        {
            Usuario oUsuario = null;
            UsuarioDALC oUsuarioDALC = new UsuarioDALC();
            int resultado = 0;

            try
            {
                //Creo la entidad de negocio Usuario
                oUsuario = new Usuario(username, EncriptarPassword(password), pregunta, EncriptarPassword(respuesta));

                //Registro el nuevo usuario
                resultado = oUsuarioDALC.Insertar(oUsuario);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            return resultado;
        }
        private void SetParametros(ref SqlParameter[] arrParms, ref Usuario oUsuario)
        {
            arrParms = new SqlParameter[2];

            arrParms[0] = new SqlParameter("@pi_Usuario_username", SqlDbType.VarChar);
            arrParms[0].Direction = ParameterDirection.Input;
            arrParms[0].Value = oUsuario.Usuario_Username;

            arrParms[1] = new SqlParameter("@pi_Usuario_Password", SqlDbType.VarBinary);
            arrParms[1].Direction = ParameterDirection.Input;
            arrParms[1].Value = oUsuario.Usuario_Password;
        }
        public bool ValidarUsuario(String nombre_usuario, String password)
        {
            SqlConnection oConnection = null;
            SqlCommand oCommand = null;
            SqlParameter[] arrParms = null;
            SqlDataReader oDataReader = null;
            bool result = false;
            Usuario usuarioValidado = null;

            try
            {
                oConnection = this.Conectar();

                //Preparo el comando asociado a la conexion
                oCommand = oConnection.CreateCommand();
                oCommand.CommandType = CommandType.Text;
                oCommand.CommandText = SQL_SELECT_USUARIO;

                SetParametros(ref arrParms, nombre_usuario);

                AgregarParametros(ref oCommand, ref arrParms);

                //Ejecuto el comando
                oDataReader = oCommand.ExecuteReader();

                //Si tiene filas el SqlDataReader es porque retorno una coincidencia
                if (oDataReader.HasRows)
                {
                    //Leo el SqlReader
                    oDataReader.Read();

                    if (EstadoActivo(oDataReader))
                    {
                        if (PasswordValido(password, oDataReader))
                        {
                            //Creo el objeto usuario que esta logueandose al sistema
                            usuarioValidado = new Usuario();
                            usuarioValidado.Usuario_Username = nombre_usuario;
                            usuarioValidado.Usuario_Password = Convert.ToString(oDataReader["Usuario_Password"]);
                            usuarioValidado.Usuario_Pregunta_Secreta = (String)oDataReader["Usuario_Pregunta_Secreta"];
                            usuarioValidado.Usuario_Respuesta_Secreta = Convert.ToString(oDataReader["Usuario_Respuesta_Secreta"]);
                            usuarioValidado.Usuario_ID = Convert.ToInt32(oDataReader["Usuario_ID"]);
                            usuarioValidado.Usuario_Fecha_Creacion = (DateTime)oDataReader["Usuario_Fecha_Creacion"];
                            usuarioValidado.Usuario_Fecha_Ultima_Modif = (DateTime)oDataReader["Usuario_Fecha_Ultima_Modif"];
                            usuarioValidado.Usuario_Cantidad_Intentos = (byte)oDataReader["Usuario_Cant_Intentos"];
                            usuarioValidado.Usuario_Estado = Convert.ToBoolean(oDataReader["Usuario_Estado"]);

                            //Creo la sesión
                            Sesion.SesionActual = usuarioValidado;
                            result = true;
                        }
                        else//No matchea la password
                        {
                            int intentos = ((byte)oDataReader["Usuario_Cant_Intentos"]);
                            if (intentos < CANTIDAD_MAXIMA_INTENTOS_FALLIDOS)
                            {
                                //Sumo cant intento fallido y logueo la actividad
                                NuevoIntentoFallido(intentos + 1, Convert.ToInt32(oDataReader["Usuario_ID"]));
                                LogueoIntentoFallido(Convert.ToInt32(oDataReader["Usuario_ID"]), intentos + 1);
                                throw new PasswordIncorrectaException();
                            }
                            if (intentos == CANTIDAD_MAXIMA_INTENTOS_FALLIDOS)
                            {
                                //Deshabilito el usuario y restablezco los intentos
                                DeshabilitarUsuario(Convert.ToInt32(oDataReader["Usuario_ID"]));
                            }
                        }
                    }
                    else
                    {
                        throw new UsuarioDeshabilitadoException();
                    }
                }
                else //No matcha el username, es decir no existe el usuario
                {
                    throw new UsuarioInexistenteException();
                }
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                //Cierro la conexion
                this.Desconectar(ref oConnection);

                //Libero los recursos
                this.LiberarSQLConnection(ref oConnection);
                this.LiberarSQLCommand(ref oCommand);
                this.LiberarDataReader(ref oDataReader);
            }
            return result;
        }