public List<Gallery> GetAllGalleries(string token)
        {
            ApiHelper.ValidToken(token);
            User user = new UserLogic().RetrieveUserByToken(token);
            List<Gallery> galleries = new GalleryLogic().RetrieveGalleriesByUserId(user.UserId);

            return galleries;
        }
        public string GetTokenByUsernameAndPassword(string username, string password)
        {
            string hashedPassword = SimpleHash.ComputeHash(password, SimpleHash.Algorithm.SHA256, new byte[8]);
            User user = new UserLogic().RetrieveUserByUsernameAndPassword(username, hashedPassword);

            Guid serviceKey = user.ServiceKey;
            string token = new UserLogic().GenerateUserToken(serviceKey);

            return token;
        }
        /// <summary>
        /// Handles the Click event of the loginButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void loginButton_Click(object sender, EventArgs e)
        {
            //Clean up username and hash password
            string username = emailAddressTextBox.Text.Trim();
            string password = SimpleHash.ComputeHash(passwordTextBox.Text.Trim(), SimpleHash.Algorithm.SHA256, new byte[8]);

            bool isValidUser = new UserLogic().AuthenticateUser(username, password);

            if(!isValidUser)
            {
                message.Text = AdminResources.LoginInvalidCredentials;
            }
            else
            {
                username = Convert.ToBase64String(Encoding.ASCII.GetBytes(username));
                Authorization.SetAuthenticationCookie(username, password);
                Response.Redirect(AdminResources.AdminHomepage, true);
            }
        }
 public string GetToken(Guid serviceKey)
 {
     string userToken = new UserLogic().GenerateUserToken(serviceKey);
     return userToken;
 }
        // private const string defaultIV = "ZVuQgawmoCN5L0n0";
        /// <summary>
        /// Authenticateds the user.
        /// </summary>
        /// <returns></returns>
        public bool AuthenticatedUser()
        {
            bool isValidUser = false;
            HttpCookie cookie = HttpContext.Current.Request.Cookies[AdminResources.AuthenticationCookieName];

            if (cookie != null)
            {
                cookie = DecryptCookie(cookie);

                username = cookie["Username"];
                password = cookie["Password"];

                username = Encoding.ASCII.GetString(Convert.FromBase64String(username));
                isValidUser = new  UserLogic().AuthenticateUser(username, password);
            }

            return isValidUser;
        }
 /// <summary>
 /// Retrieves the user.
 /// </summary>
 /// <returns></returns>
 public User RetrieveUser()
 {
     User user = new UserLogic().RetrieveUserByUsernameAndPassword(username, password);
     return user;
 }
        /// <summary>
        /// Sets the authorized user.
        /// </summary>
        /// <param name="authorize">The authorize.</param>
        private void SetAuthorizedUser(Authorization authorize)
        {
            User user = authorize.RetrieveUser();

            HttpCookie sessionCookie = new HttpCookie(AdminResources.AdminSessionCookieName);
            sessionCookie["Token"] = new UserLogic().GenerateUserToken(user.ServiceKey);
            sessionCookie["Meat"] = "Chicken";
            sessionCookie.Expires = DateTime.Now.AddMonths(1);

            Authorization.SetUnencryptedCookie(sessionCookie);

            CurrentUser = user;
            Thread.CurrentPrincipal = CurrentUser;
        }