Beispiel #1
0
        public void TestSaltCopy()
        {
            Salt s = new Salt();
            byte[] bytes = new byte[s.Length];
            s.CopyTo(bytes, 0);
            Assert.AreEqual(s.ToArray(), bytes);
            Assert.AreEqual(s.GetHashCode(), Salt.FromBytes(bytes).GetHashCode());

			Salt strcpy = Salt.FromString(s.ToString());
			Assert.AreEqual(s.ToArray(), strcpy.ToArray());
			Assert.AreEqual(s.ToString(), strcpy.ToString());
			Assert.AreEqual(s.GetHashCode(), strcpy.GetHashCode());
		}
Beispiel #2
0
        public void TestSaltCopy()
        {
            Salt s = new Salt();

            byte[] bytes = new byte[s.Length];
            s.CopyTo(bytes, 0);
            Assert.AreEqual(s.ToArray(), bytes);
            Assert.AreEqual(s.GetHashCode(), Salt.FromBytes(bytes).GetHashCode());

            Salt strcpy = Salt.FromString(s.ToString());

            Assert.AreEqual(s.ToArray(), strcpy.ToArray());
            Assert.AreEqual(s.ToString(), strcpy.ToString());
            Assert.AreEqual(s.GetHashCode(), strcpy.GetHashCode());
        }
        protected void btnContinue_Click(object sender, EventArgs e)
        {
            string message = string.Empty;
            if (txtForgetEmail.Text != null)
            {
                string email = txtForgetEmail.Text;
                customer customerObj = new customer();

                if (customerObj.existCustomerByEmail(email))
                {
                    Salt generatedCode = new Salt();
                    Session["email"] = email;
                    Session["role"] = "customer";
                    customerObj.insertGeneratedCode(generatedCode.ToString(), email);
                    string emailFrom = "*****@*****.**";
                    string emailTo = email;
                    string subject = "Reset password";

                    message = "You have requested to change your password. Click <a href='Client_ResetPassword.aspx?code='"+generatedCode+"''> here</a> to reset you password.";

                    Email objEmail = new Email();
                    objEmail.SendMail(emailTo, emailFrom, subject, message);
                    lblMsg1.Text = "The email was sent.";
                }
                else
                    lblMsg1.Text = "This email is not connected to any account!";
            }
            else
            {
                lblMsg1.Text = "Please fill the form with the new password";

            }
        }
        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtCurrentEmail.Text) || String.IsNullOrEmpty(txtCurrentPassword.Text) || String.IsNullOrEmpty(txtNewPassword.Text))
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "<script> alert('All fields are required.Thank you!'); </script>");

            SqlCommand pass = new SqlCommand();
            DBConnect objDB = new DBConnect();

            //string currentPassword = (string)pass.ExecuteScalar();
            //if (currentPassword == txtCurrentPassword.Text)
            //     { }

            //else
            //    lblMsg.Text = "Please enter your current password again!";
            Salt salt = new Salt();
            string currentEmail = txtCurrentEmail.Text;
            string currentPassword = txtCurrentPassword.Text;
            string newPassword1 = txtNewPassword.Text;
            customer customerObj=new customer();
            int result = customerObj.ResetPassword(currentEmail, currentPassword, newPassword1, salt.ToString(),role);
            if (result == 0)
                lblMsg.Text = "The password you entered is incorrect!";

            else if (result == 1)
                lblMsg.Text = "The password was changed successfully.";
            //  Response.Redirect("LoginPage.aspx");
        }
Beispiel #5
0
        public void When_SaltProvidedAsString_Expect_CanCast()
        {
            Salt salt = testSaltString;

            Assert.NotNull(salt);
            Assert.AreEqual(testSaltString, salt.ToString());
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtNewPassword1.Text) || String.IsNullOrEmpty(txtNewPassword2.Text))
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "<script> alert('All fields are required.Thank you!'); </script>");

            if (canChangePass)
            {

                Salt salt = new Salt();
                string password1 = txtNewPassword1.Text;
                string password2 = txtNewPassword2.Text;
                if (txtNewPassword1.Text == txtNewPassword2.Text)
                {
                    customer customerObj = new customer();
                    string role = "customer";
                    int result = customerObj.ResetPassword(email, null, password1, salt.ToString(),role);

                    if (result == 0)
                        lblMsg.Text = "The password you entered is incorrect!";

                    else if (result == 1)
                        lblMsg.Text = "The password was changed successfully.";

                }

            }
            else
                lblMsg.Text = "You do not have authorization to access this email address.";
        }
Beispiel #7
0
 public string toClientData()
 {
     return(string.Format("\"{0}\",{1},{2},{3},\"{4}\",{5},{6},{7},{8},{9},{10},{11},{12},{13}, \"{14}\"", Name, Id, (Category)? 1 : 0,
                          Price.ToString("0.00", CultureInfo.InvariantCulture), Composition, EnergyKj, EnergyKcal,
                          Protein.ToString("0.00", CultureInfo.InvariantCulture), Carbohydrates.ToString("0.00", CultureInfo.InvariantCulture),
                          Sugar.ToString("0.00", CultureInfo.InvariantCulture), TotalFat.ToString("0.00", CultureInfo.InvariantCulture),
                          SaturatedFat.ToString("0.00", CultureInfo.InvariantCulture), Fiber.ToString("0.00", CultureInfo.InvariantCulture),
                          Salt.ToString("0.00", CultureInfo.InvariantCulture), Path));
 }
Beispiel #8
0
        public void When_SaltProvided_Expect_CanConvertStringAndByteArray()
        {
            Salt saltString = new Salt(testSaltString);
            Salt saltBytes  = new Salt(Encoding.UTF8.GetBytes(saltString));

            Assert.AreNotSame(saltString, saltBytes);
            Assert.AreEqual(saltString.ToString(), testSaltString);
            Assert.AreEqual(saltBytes.ToString(), testSaltString);
            Assert.AreEqual(saltBytes.Value, saltString.Value);
        }
Beispiel #9
0
        public void When_SaltProvidedAsByteArray_Expect_CanCast()
        {
            var mySalt = Encoding.UTF8.GetBytes(testSaltString);

            Salt salt = mySalt;

            Assert.NotNull(salt);
            Assert.AreEqual(testSaltString, salt.ToString());
            Assert.AreEqual(mySalt, salt.Value);
            Assert.AreNotSame(mySalt, salt.Value);
        }
Beispiel #10
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendFormat("Salt: {0}\n", Salt.ToString("X"));
            sb.AppendFormat("SessionId: {0}\n", SessionId.ToString("X"));
            sb.AppendFormat("SeqNo: {0}\n", SeqNo);
            sb.AppendFormat("MessageId: {0}\n", MessageId.ToString("X"));
            sb.AppendFormat("MessageDataLength: {0}\n", MessageDataLength);
            sb.AppendFormat("Plain MessageData: {0}\n", BinaryHelper.ByteToHexBitFiddle(MessageData));

            return(sb.ToString());
        }
Beispiel #11
0
        public async Task <ActionResult> PostUser([FromBody] int id, string password, string token)
        {
            var user = await _context.User.FindAsync(id);

            if (UserExists(id) && user.Token == token)
            {
                var    passwordSalt = new Salt();
                string passwordHash = Hash.Create(user.Password, passwordSalt.ToString());
                user.Password = passwordHash;
                await _context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Beispiel #12
0
 public string StringInfo()
 {
     return("Caramel: " + Caramel.ToString() + "\nChesse: " + Chesse.ToString() +
            "\nBacon: " + Bacon.ToString() + "\nSalted: " + Salt.ToString() +
            "\nSugar: " + Sugar.ToString() + "\nChocolate: " + Chocolate.ToString());
 }