示例#1
0
        public static void Login(string username, string password)
        {
            try
            {
                SHA256Managed crypt = new SHA256Managed();
                //string hash = String.Empty;
                byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
                /*
                foreach (byte bit in crypto)
                {
                    hash += bit.ToString("x2");
                }
                */
                using (SqlConnection conn = Conexion.Conexion.obtenerConexion())
                {
                    SqlParameter returnValue = new SqlParameter() { Direction = ParameterDirection.ReturnValue };

                    SqlCommand com = new SqlCommand("[NORMALIZADOS].[Login]", conn);

                    com.CommandType = CommandType.StoredProcedure;
                    com.Parameters.AddWithValue("@Username", username);
                    com.Parameters.AddWithValue("@SHA256", crypto);
                    com.Parameters.Add(returnValue);

                    com.ExecuteScalar();

                    int id = Convert.ToInt32(returnValue.Value);

                    UsuarioDTO usuario = new UsuarioDTO() { ID_User = id, Username = username };

                    usuario.Roles = RolDAO.SelectByUser(usuario);

                    UsuarioActual = usuario;

                    logued = true;

                }

            }
            catch (SqlException ex)
            {
                if (ex.Number == 50000) //Si es una exception que lancé yo.
                    throw new ApplicationException(ex.Message);
                else throw ex;
            }
        }
示例#2
0
 public static void Logout()
 {
     logued = false;
     UsuarioActual = DefaultUser();
 }
示例#3
0
 public static void StartAsClient()
 {
     UsuarioActual = DefaultUser();
     RolActual = Roles[0];
 }
示例#4
0
 public static List<RolDTO> SelectByUser(UsuarioDTO usuario)
 {
     using (SqlConnection conn = Conexion.Conexion.obtenerConexion())
     {
         SqlCommand com = new SqlCommand("SELECT R.Id,R.Nombre,R.Activo FROM [NORMALIZADOS].Usuario U JOIN [NORMALIZADOS].Rol R ON U.Rol=R.Id WHERE U.Id=" + usuario.ID_User, conn);
         SqlDataReader dataReader = com.ExecuteReader();
         return ReaderToListClaseRol(dataReader);
     }
 }