protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        UsersLogic users = new UsersLogic();

        IEnumerable <User> usersList = users.GetUsers();

        foreach (User user in usersList)
        {
            // convert the password to bytes array
            byte[] passBytes = Convert.FromBase64String(user.Password);
            // get the salt array with the default SaltSize in 'MyWebAuthentication'
            byte[] salt = new byte[MyWebAuthentication.SaltSize];
            // fill the salt array with the values from passBytes
            Array.Copy(passBytes, 0, salt, 0, 16);

            // now i have the salt and i can hash the password that the user enterd
            string password       = txtPassword.Text;
            string hashedPassword = MyWebAuthentication.HashPassword(password, salt);
            // the email that was entered
            string email = txtEmail.Text.ToLower();

            // compare the two hashed passwords
            if (MyWebAuthentication.CompareHashedPasswords(hashedPassword, user.Password) == true &&
                email == user.Email)    // check if the email is correct also
            {
                // if password founds equal set the validator to valid and finish!
                args.IsValid = true;
                // set userID in the session
                MyWebAuthentication.UserID = user.UserID;
                return;
            }
        }
        // if no found equal password
        args.IsValid = false;
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // disable caching for masterpage (so that OutputCache will not cache this pages)
        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
        // check if user is log on
        if (MyWebAuthentication.IsUserLogOn())
        {
            UsersLogic users = new UsersLogic();
            // if he is log on thats mean i can access to his userID:
            User user = users.GetUser(MyWebAuthentication.UserID);
            // set the userName inside the button
            btnUserOptions.Text = user.UserName;
            // hide the two links of signin and signup
            lnkSignIn.Visible = lnkSignUp.Visible = false;

            // if the user is Admin show link to AdminPage
            if (user.IsAdmin == true)
            {
                lnkLinkToAdmin.Visible = true;
            }
        }
        else// hide the button that sould hold the userName if the user is not login
        {
            btnUserOptions.Visible = false;
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (MyWebAuthentication.IsUserLogOn())
     {
         Response.Redirect("Member?u=" + MyWebAuthentication.UserID);
     }
 }
Exemple #4
0
    protected void btnSignUp_Click(object sender, EventArgs e)
    {
        if (IsValid == false)
        {
            return;
        }

        User user = new User()
        {
            FirstName = txtFirstName.Text,
            LastName  = txtLastName.Text,
            Email     = txtEmail.Text.ToLower(),
            Phone     = txtPhone.Text,
            UserName  = txtUserName.Text
        };

        string password = txtPassword.Text;

        user.Password = MyWebAuthentication.HashPassword(password); // hash the pass with 16 SaltSize (default set)

        try
        {
            users.CreateNewUser(user);
        }
        catch { }

        MyWebAuthentication.UserID = users.GetUser(user.Email).UserID;

        Response.Redirect("Member?u=" + MyWebAuthentication.UserID); // need to create a page called "memeber"
    }
Exemple #5
0
 protected void btnUserLogOut_Click(object sender, EventArgs e)
 {
     // log out and go to HomePage
     if (MyWebAuthentication.IsUserLogOn())
     {
         MyWebAuthentication.LogOut("HomePage");
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (MyWebAuthentication.IsUserLogOn() == false)
        {
            SetMessageState(State.Danger, "דף זה זמין רק למשתמשים רשומים!!");
            pnlOrderPanel.Visible = false;
            Title = "Error";
            return;
        }

        if (string.IsNullOrEmpty(Request.QueryString.Get("showID")) == true)
        {
            Response.Redirect("HomePage#shows");
        }

        // check if there is 'showID' string in QueryString
        // and then try parse (because sould be only intger)
        bool isIntger = int.TryParse(Request.QueryString.Get("showID"), out _showID);

        ShowsLogic shows = new ShowsLogic();

        if (isIntger == false || shows.IsShowExists(_showID) == false)
        {
            SetMessageState(State.Warning, "הופעה לא נמצאה!");
            pnlOrderPanel.Visible = false;
            Title = "Error";
            return;
        }

        Show show = shows.GetShow(_showID);

        Title = show.ShowTitle;

        lblShowTitle.Text     = show.ShowTitle;
        lblShowDate.Text      = show.ShowDate.ToLongDateString();
        lblShowDiscount.Text  = show.ShowDiscount.ToString();
        lblShowAddress.Text   = show.ShowAddress;
        lblShowComments.Text  = show.Comments;
        lblShowCardPrice.Text = show.ShowCardPrice.ToString();

        decimal price              = Convert.ToInt32(show.ShowCardPrice);
        decimal discount           = Convert.ToInt32(show.ShowDiscount);
        decimal priceAfterDiscount = price * (1 - discount / 100);

        lblCardPriceAfterDiscount.Text = Convert.ToString(priceAfterDiscount);

        imgShowImageUrl.ImageUrl = show.ShowImageUrl;

        string userName = users.GetUser(MyWebAuthentication.UserID).UserName;

        if (orders.IsUserOrderShow(userName, _showID))
        {
            lblHasOrdered.Attributes.Add("title", "כבר הזמנת כרטיסים להופעה הזאת!");
            lblHasOrdered.Visible = true;
        }
    }
Exemple #7
0
    const string _emailAddressToSend = "email";    // email to send the notification message (the website owner)

    protected void Page_Load(object sender, EventArgs e)
    {
        // check if the user is log on and if he is:
        // put his firstName and lastName and Email automatically in the TextBoxs
        if (MyWebAuthentication.IsUserLogOn())
        {
            UsersLogic users = new UsersLogic();
            User       user  = users.GetUser(MyWebAuthentication.UserID);

            txtFullName.Text = user.FirstName + " " + user.LastName;
            txtEmail.Text    = user.Email;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (MyWebAuthentication.IsUserLogOn())
        {
            UsersLogic users = new UsersLogic();
            User       user  = users.GetUser(MyWebAuthentication.UserID);

            Title = user.UserName;

            string fullName = user.FirstName + " " + user.LastName;

            lblFullName.Text = fullName;
        }
        else
        {
            Response.Redirect("HomePage");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // checking if the user logged in
        if (MyWebAuthentication.IsUserLogOn())
        {
            int userID = MyWebAuthentication.UserID;
            // checking if he is Admin, if he is not send him to HomePage
            if (users.IsAdmin(userID) == false)
            {
                Response.Redirect("HomePage", true);
            }
        }
        else // if not logged in send him to HomePage
        {
            Response.Redirect("HomePage", true);
        }

        // setting the 'min' attribute to <input type=date> so he can choose only the future days.
        string dateFormat = string.Format("{0}-{1:D2}-{2:D2}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

        txtShowDate.Attributes.Add("min", dateFormat);
    }