Example #1
0
        protected void hashFunction(object sender, EventArgs e)
        {
            string    plain = plainText.Text;
            ExLibrary lib   = new ExLibrary();

            if (!string.IsNullOrEmpty(plain))
            {
                HashText.Text    = lib.hash(plain);
                HashText.Visible = true;
            }
            else
            {
                HashText.Text    = "Please enter a text to convert into hash";
                HashText.Visible = true;
            }
        }
Example #2
0
        //LogsIn the User
        protected void Login_User(object sender, EventArgs e)
        {
            ErrorMessage.Text    = null;
            ErrorMessage.Visible = false;
            ExLibrary library  = new ExLibrary();
            string    userName = UserName.Text.Trim();
            string    pass     = password.Text.Trim();
            //Authenticates an user gets the corresponding Role
            string role = XmlOperations.authenticateMember(userName, library.hash(pass));

            //If login successfull
            if (!role.Equals("INVALID"))
            {
                var roles = new[] { role };

                //Set an authorisation cookie used for consequent logins
                FormsAuthentication.SetAuthCookie(userName, true);

                //Ticket store userdata in the cookie
                FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(10), true, string.Join(",", roles), FormsAuthentication.FormsCookiePath);

                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket1));
                if (!Persistent.Checked)
                {
                    cookie.Expires = ticket1.Expiration;
                }

                //Add the encrypted cookie to the Response
                Response.Cookies.Add(cookie);

                //If there isn't a redirection to login page
                string returnUrl = Request.QueryString["returnUrl"];
                if (string.IsNullOrEmpty(returnUrl))
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Response.Redirect(returnUrl, true);
                }
            }
            else
            {
                ErrorMessage.Text    = "Invalid UserName and Password. Try Again.";
                ErrorMessage.Visible = true;
            }
        }
Example #3
0
        /*
         * Creates a new user
         */
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            ErrorMessage.Visible = false;
            ErrorMessage.Text    = null;
            string memberName  = MemberName.Text;
            string userName    = Email.Text;
            string password    = Password.Text;
            string confirmPass = ConfirmPassword.Text;

            bool status = false;

            //If the page validation is susscessfull
            if (IsValid)
            {
                if (inputImgVerify.Text.Trim() == captchaImage)
                {
                    //Use the DLL library to hash
                    ExLibrary explorerLibrary = new ExLibrary();
                    string    hashPassword    = explorerLibrary.hash(password);
                    //Use the XmlOperations to add a new user to Members.Xml.
                    status = XmlOperations.createMember(memberName, userName, hashPassword);
                }
                else
                {
                    ErrorMessage.Text    = "Please enter correct Captcha.";
                    ErrorMessage.Visible = true;
                    return;
                }
            }

            if (status)
            {
                //If addition is successfull, navigate user to Login
                Response.Redirect("Login.aspx");
            }
            else
            {
                ErrorMessage.Text    = "Unable to create a User. Please try again.";
                ErrorMessage.Visible = true;
            }
        }