Esempio n. 1
0
        public bool HasValidHash(string input, out string hash)
        {
            hash = "";
            if (_hashGenerator.ComputeHash(input, out string fullhash))
            {
                hash = fullhash;
                return(fullhash.Substring(0, 5).Equals("00000"));
            }

            return(false);
        }
Esempio n. 2
0
        public bool PasswordMatches(string password)
        {
            var hashedBuffer = HashGenerator.ComputeHash(Encoding.ASCII.GetBytes(password), HashAlgorithm.SHA256);

            if (PasswordHash.Length != hashedBuffer.Length)
            {
                return(false);
            }
            for (int i = 0; i < PasswordHash.Length; i++)
            {
                if (PasswordHash[i] != hashedBuffer[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
        public void IdenticonRequest_Extended()
        {
            var url1 = new IdenticonRequest
            {
                Hash  = HashGenerator.ComputeHash("Hello", "SHA1"),
                Size  = 741,
                Style = new IdenticonStyle
                {
                    Padding             = 0.3f,
                    BackColor           = Color.Bisque,
                    ColorLightness      = Range.Create(0.25f, 0.75f),
                    GrayscaleLightness  = Range.Create(0, 1f),
                    ColorSaturation     = 0.4f,
                    GrayscaleSaturation = 0.1f,
                    Hues = new HueCollection {
                        1.5f, -0.25f, 0.8f
                    }
                }
            };

            var text = url1.ToString();

            Assert.IsTrue(IdenticonRequest.TryParse(text, out var url2));

            Assert.AreEqual(url1.Format, url2.Format);
            Assert.AreEqual(url1.Style.BackColor.ToRgba(), url2.Style.BackColor.ToRgba());
            AssertAreAlmostEqual(url1.Style.Padding, url2.Style.Padding);
            AssertAreAlmostEqual(url1.Style.ColorLightness.From, url2.Style.ColorLightness.From);
            AssertAreAlmostEqual(url1.Style.ColorLightness.To, url2.Style.ColorLightness.To);
            AssertAreAlmostEqual(url1.Style.GrayscaleLightness.From, url2.Style.GrayscaleLightness.From);
            AssertAreAlmostEqual(url1.Style.GrayscaleLightness.To, url2.Style.GrayscaleLightness.To);

#pragma warning disable 0618
            AssertAreAlmostEqual(url1.Style.ColorSaturation, url2.Style.Saturation);
#pragma warning restore 0618

            AssertAreAlmostEqual(url1.Style.ColorSaturation, url2.Style.ColorSaturation);
            AssertAreAlmostEqual(url1.Style.GrayscaleSaturation, url2.Style.GrayscaleSaturation);
            Assert.AreEqual(3, url2.Style.Hues.Count);
            AssertAreAlmostEqual(0.5f, url2.Style.Hues[0]);
            AssertAreAlmostEqual(0.75f, url2.Style.Hues[1]);
            AssertAreAlmostEqual(0.8f, url2.Style.Hues[2]);

            Assert.AreEqual(url1.Size, url2.Size);
        }
Esempio n. 4
0
        public void IdenticonRequest_Compact_SizeMultipleOf5()
        {
            var url1 = new IdenticonRequest
            {
                Hash = HashGenerator.ComputeHash("Hello", "SHA1"),
                Size = 65
            };

            var text = url1.ToString();

            Assert.IsTrue(IdenticonRequest.TryParse(text, out var url2));

            Assert.AreEqual(url1.Format, url2.Format);
            Assert.AreEqual(url1.Style.BackColor.ToRgba(), url2.Style.BackColor.ToRgba());
            AssertAreAlmostEqual(url1.Style.Padding, url2.Style.Padding);
            AssertAreAlmostEqual(url1.Style.ColorLightness.From, url2.Style.ColorLightness.From);
            AssertAreAlmostEqual(url1.Style.ColorLightness.To, url2.Style.ColorLightness.To);
            AssertAreAlmostEqual(url1.Style.GrayscaleLightness.From, url2.Style.GrayscaleLightness.From);
            AssertAreAlmostEqual(url1.Style.GrayscaleLightness.To, url2.Style.GrayscaleLightness.To);

            Assert.AreEqual(url1.Size, url2.Size);
        }
Esempio n. 5
0
        public void IdenticonRequest_DefaultStyle()
        {
            var url1 = new IdenticonRequest
            {
                Hash  = HashGenerator.ComputeHash("Hello", "SHA1"),
                Size  = 741,
                Style = new IdenticonStyle
                {
                    Padding = 0.3f
                }
            };

            try
            {
                var text = url1.ToString();
                Assert.IsTrue(IdenticonRequest.TryParse(text, out var url2));

                AssertAreAlmostEqual(0.3f, url2.Style.Padding);
                Identicon.DefaultStyle.Padding = 0.1f;
                AssertAreAlmostEqual(0.3f, url2.Style.Padding);

                Identicon.DefaultStyle.Padding = 0.3f;

                text = url1.ToString();
                Assert.IsTrue(IdenticonRequest.TryParse(text, out var url3));

                AssertAreAlmostEqual(0.3f, url3.Style.Padding);
                Identicon.DefaultStyle.Padding = 0.2f;

                Assert.IsTrue(IdenticonRequest.TryParse(text, out var url4));
                AssertAreAlmostEqual(0.2f, url4.Style.Padding);
            }
            finally
            {
                // Restore default style so that other tests are not affected
                Identicon.DefaultStyle = null;
            }
        }
Esempio n. 6
0
        /// <inheritdoc cref="Identicon(IHtmlHelper, Jdenticon.Identicon, int, string, ExportImageFormat)" />
        /// <summary>
        /// Renders an identicon as an IMG tag.
        /// </summary>
        /// <param name="helper">The <see cref="IHtmlHelper"/>.</param>
        /// <param name="value">The value that will be hashed and used as base for the icon.</param>
        /// <param name="size">The size of the generated icon in pixels.</param>
        /// <param name="alt">The alt attribute of the rendered image.</param>
        /// <param name="style">The icon style.</param>
        /// <param name="format">The file format of the generated icon.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> was less than 1.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="helper"/> was <c>null</c>.</exception>
        public static IHtmlContent Identicon(this IHtmlHelper helper, object value, int size, string alt = null, ExportImageFormat format = ExportImageFormat.Png, IdenticonStyle style = null)
        {
            var hash = HashGenerator.ComputeHash(value, "SHA1");

            return(helper.Identicon(hash, size, alt, format, style));
        }
Esempio n. 7
0
 public void ChangePassword(string password)
 {
     PasswordHash = HashGenerator.ComputeHash(Encoding.ASCII.GetBytes(password), HashAlgorithm.SHA256);
     PushPasswordHistory();
 }
Esempio n. 8
0
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            ResetBorderColors();
            if (sluzbenik != null)
            {
                if (!izmjena)
                {
                    textBox_Ime.IsEnabled             = true;
                    textBox_Prezime.IsEnabled         = true;
                    textBox_Email.IsEnabled           = true;
                    textBox_BrojTelefona.IsEnabled    = true;
                    textBox_KorisnickoIme.IsEnabled   = true;
                    textBox_Lozinka.IsEnabled         = true;
                    textBox_LozinkaProvjera.IsEnabled = true;

                    Button1.Content = uredu;
                    Button2.Content = otkazi;
                    izmjena         = true;
                }
                else
                {
                    if (!String.IsNullOrEmpty(textBox_Ime.Text) &&
                        !String.IsNullOrEmpty(textBox_Prezime.Text) &&
                        !String.IsNullOrEmpty(textBox_Email.Text) &&
                        !String.IsNullOrEmpty(textBox_BrojTelefona.Text) &&
                        !String.IsNullOrEmpty(textBox_KorisnickoIme.Text) &&
                        textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password))
                    {
                        try
                        {
                            using (var ersteModel = new ErsteModel())
                            {
                                sluzbenik                    = ersteModel.sluzbenici.Find(sluzbenik.Id);
                                sluzbenik.osoba.Ime          = textBox_Ime.Text;
                                sluzbenik.osoba.Prezime      = textBox_Prezime.Text;
                                sluzbenik.osoba.Email        = textBox_Email.Text;
                                sluzbenik.osoba.BrojTelefona = textBox_BrojTelefona.Text;
                                sluzbenik.KorisnickoIme      = textBox_KorisnickoIme.Text;
                                if (!String.IsNullOrEmpty(textBox_Lozinka.Password))
                                {
                                    HashGenerator hashGenerator = new HashGenerator();
                                    sluzbenik.LozinkaHash = hashGenerator.ComputeHash(textBox_Lozinka.Password);
                                }
                                ersteModel.SaveChanges();
                                MessageBox.Show("Korisnik je uspješno izmijenjen.");
                                Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("MySQL Exception: " + ex.ToString());
                        }
                    }
                    else
                    {
                        if (!textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password))
                        {
                            MessageBox.Show("Lozinke moraju biti iste.");
                        }
                        else
                        {
                            MessageBox.Show("Sva polja moraju biti popunjena.");
                            var textBoxes = grid.Children.OfType <TextBox>();
                            foreach (var t in textBoxes)
                            {
                                if (String.IsNullOrEmpty(t.Text))
                                {
                                    t.BorderBrush = Brushes.Red;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(textBox_Ime.Text) &&
                    !String.IsNullOrEmpty(textBox_Prezime.Text) &&
                    !String.IsNullOrEmpty(textBox_Email.Text) &&
                    !String.IsNullOrEmpty(textBox_BrojTelefona.Text) &&
                    !String.IsNullOrEmpty(textBox_KorisnickoIme.Text) &&
                    textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password))
                {
                    sluzbenik sluzbenik = new sluzbenik();
                    sluzbenik.osoba              = new osoba();
                    sluzbenik.osoba.Ime          = textBox_Ime.Text;
                    sluzbenik.osoba.Prezime      = textBox_Prezime.Text;
                    sluzbenik.osoba.Email        = textBox_Email.Text;
                    sluzbenik.osoba.BrojTelefona = textBox_BrojTelefona.Text;
                    sluzbenik.KorisnickoIme      = textBox_KorisnickoIme.Text;

                    HashGenerator hashGenerator = new HashGenerator();
                    sluzbenik.LozinkaHash = hashGenerator.ComputeHash(textBox_Lozinka.Password);

                    try
                    {
                        using (var ersteModel = new ErsteModel())
                        {
                            ersteModel.sluzbenici.Add(sluzbenik);
                            ersteModel.SaveChanges();
                            Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("MySQL Exception: " + ex.ToString());
                    }
                }
                else
                {
                    if (!textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password))
                    {
                        MessageBox.Show("Lozinke moraju biti iste.");
                    }
                    else
                    {
                        MessageBox.Show("Sva polja moraju biti popunjena.");
                        var textBoxes = grid.Children.OfType <TextBox>();
                        foreach (var t in textBoxes)
                        {
                            if (String.IsNullOrEmpty(t.Text))
                            {
                                t.BorderBrush = Brushes.Red;
                            }
                        }
                    }
                }
            }
        }
        public static string Identicon(this IUrlHelper helper, object?value, int size, ExportImageFormat format = ExportImageFormat.Png, IdenticonStyle?style = null)
        {
            var hash = HashGenerator.ComputeHash(value, "SHA1");

            return(helper.Identicon(hash, size, format, style));
        }
 public void GenerateHash()
 {
     var hash = HashGenerator.ComputeHash("admin");
 }
Esempio n. 11
0
 public void HashUtils_Null()
 {
     Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", HexString.ToString(HashGenerator.ComputeHash(null, "MD5")));
 }
Esempio n. 12
0
 public void HashUtils_String()
 {
     Assert.AreEqual("827ccb0eea8a706c4c34a16891f84e7b", HexString.ToString(HashGenerator.ComputeHash("12345", "MD5")));
 }