예제 #1
0
파일: LogIn.cs 프로젝트: tvdlans/NoSQL
        private void btnSubmitNewPswd_Click(object sender, EventArgs e)
        {
            string password    = txtNewPswd.Text;
            string rptPassword = txtRepeatPswd.Text;

            //check if the new password is valid
            if (string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(rptPassword))
            {
                MessageBox.Show("Fields can't be empty");
            }
            else if (password != rptPassword)
            {
                MessageBox.Show("Passwords do not match");
            }
            else
            {
                //update password
                Login   login      = new Login();
                ConUser conUser    = new ConUser();
                string  hashedpswd = conUser.HashPassword(password);
                login.ConUpdatePassword(email, hashedpswd);
                pnlforgotpswd.Hide();
                pnlCode.Hide();
                pnlNewPswd.Hide();
                MessageBox.Show("Password updated");
            }
        }
예제 #2
0
파일: LogIn.cs 프로젝트: tvdlans/NoSQL
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Login   login   = new Login();
            ConUser conUser = new ConUser();

            email = txtEmail.Text;
            string       password   = txtPassword.Text;
            string       hashedpswd = conUser.HashPassword(password);
            BsonDocument user       = login.CheckUser(email, password);

            if (user != null)
            {
                if (user.GetElement("Password").Value.ToString() == hashedpswd)
                {
                    // makes the remember me function work
                    if (chkremember.Checked == true)
                    {
                        Properties.Settings.Default.Name     = txtEmail.Text;
                        Properties.Settings.Default.Password = password;
                        Properties.Settings.Default.Save();
                    }
                    if (chkremember.Checked == false)
                    {
                        Properties.Settings.Default.Name     = "";
                        Properties.Settings.Default.Password = "";
                        Properties.Settings.Default.Save();
                    }

                    // add a "session" of the user that is logged in, that way you can access his or her information in the main program
                    ConSession session = new ConSession();
                    session.AddSession(user.GetElement("FirstName").Value.ToString(), user.GetElement("Email").Value.ToString(), ObjectId.Parse(user.GetElement("_id").Value.ToString()));

                    this.Hide();

                    // checks if the user is a service desk employee or a employee
                    if (int.Parse(user.GetElement("Role").Value.ToString()) == 0)
                    {
                        Employee employee = new Employee();
                        employee.Show();
                    }
                    else
                    {
                        Form1 form1 = new Form1();
                        form1.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Email and Password combination is not valid");
                }
            }
            else
            {
                MessageBox.Show("This user doesn't exist");
            }
        }