コード例 #1
0
 public bool validateUserLogin()
 {
     try{
         UserServiceModel user = getDatabaseUser(this.Usuario);
         if (user.Usuario == this.Usuario)
         {
             if (user.Contrasena == this.Contrasena)
             {
                 return(true);
             }
             else
             {
                 throw new Exception("La contraseña es incorrecta");
             }
         }
         else
         {
             throw new Exception("No existe el usuario ");
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
        public UserServiceModel getDatabaseUser(string userId)
        {
            UserServiceModel usuario = null;
            ActiveRecord     record  = new ActiveRecord();

            using (SqlConnection con = new SqlConnection(this.cadenaConexion))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("SELECT * FROM CuentaGastosUsuarios WHERE Usuario = @User", con);
                    cmd.Parameters.Add(new SqlParameter("@User", SqlDbType.VarChar)).Value = userId;
                    SqlDataReader reader = cmd.ExecuteReader();
                    reader.Read();
                    if (reader.HasRows)
                    {
                        usuario = new UserServiceModel
                        {
                            Usuario            = reader.GetString(1).ToString(),
                            Contrasena         = reader.GetString(2).ToString(),
                            Correo             = reader.GetString(3).ToString(),
                            Nombre             = reader.GetString(4).ToString(),
                            ApellidoPaterno    = reader.GetString(5).ToString(),
                            ApellidoMaterno    = reader.GetString(6).ToString(),
                            CodigoAcreditacion = reader.GetString(7).ToString(),
                            Perfil             = reader.GetString(8).ToString()
                        };
                        return(usuario);
                    }
                    else
                    {
                        throw new ArgumentException("No se obtuvuieron registros");
                    }
                }
                catch (Exception ex)
                {
                    con.Close();
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }
        }