CSharpTest.Net
PasswordHash Constructor(Password,Salt)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > PasswordHash Class > PasswordHash Constructor : PasswordHash Constructor(Password,Salt)

bytes
salt

Glossary Item Box

Creates a salted hash from the given password and salt

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal bytes As Password, _
   ByVal salt As Salt _
)
C# 
public PasswordHash( 
   Password bytes,
   Salt salt
)

Parameters

bytes
salt

Example

Library/Library.Test/TestPasswordHash.cs

C#Copy Code
using (PasswordHash pwd1 = new PasswordHash(TEST_PASSWORD))
{
    //no salt provided
    using (PasswordHash pwd2 = new PasswordHash(TEST_PASSWORD))
        Assert.AreNotEqual(pwd1, pwd2);
    using (PasswordHash pwd2 = new PasswordHash(false, Password.Encoding.GetBytes(TEST_PASSWORD)))
        Assert.AreNotEqual(pwd1, pwd2);
    //identical salt
    using (PasswordHash pwd2 = new PasswordHash(TEST_PASSWORD, pwd1.Salt))
        Assert.AreEqual(pwd1, pwd2);
    using (PasswordHash pwd2 = new PasswordHash(false, Password.Encoding.GetBytes(TEST_PASSWORD), pwd1.Salt))
        Assert.AreEqual(pwd1, pwd2);
    using (PasswordHash pwd2 = new PasswordHash(new MemoryStream(Password.Encoding.GetBytes(TEST_PASSWORD)), pwd1.Salt))
        Assert.AreEqual(pwd1, pwd2);

    using (PasswordHash pwd2 = new PasswordHash(new Password(TEST_PASSWORD), pwd1.Salt))
        Assert.AreEqual(pwd1, pwd2);
    using (SecureString sstr = SecureStringUtils.Create(TEST_PASSWORD))
    {
        using (PasswordHash pwd2 = new PasswordHash(sstr, pwd1.Salt))
            Assert.AreEqual(pwd1, pwd2);
        using (PasswordHash pwd2 = new PasswordHash(sstr))
            Assert.AreNotEqual(pwd1, pwd2);
    }
}
VB.NETCopy Code
Using pwd1 As New PasswordHash(TEST_PASSWORD)
    'no salt provided
    Using pwd2 As New PasswordHash(TEST_PASSWORD)
        Assert.AreNotEqual(pwd1, pwd2)
    End Using
    Using pwd2 As New PasswordHash(False, Password.Encoding.GetBytes(TEST_PASSWORD))
        Assert.AreNotEqual(pwd1, pwd2)
    End Using
    'identical salt
    Using pwd2 As New PasswordHash(TEST_PASSWORD, pwd1.Salt)
        Assert.AreEqual(pwd1, pwd2)
    End Using
    Using pwd2 As New PasswordHash(False, Password.Encoding.GetBytes(TEST_PASSWORD), pwd1.Salt)
        Assert.AreEqual(pwd1, pwd2)
    End Using
    Using pwd2 As New PasswordHash(New MemoryStream(Password.Encoding.GetBytes(TEST_PASSWORD)), pwd1.Salt)
        Assert.AreEqual(pwd1, pwd2)
    End Using

    Using pwd2 As New PasswordHash(New Password(TEST_PASSWORD), pwd1.Salt)
        Assert.AreEqual(pwd1, pwd2)
    End Using
    Using sstr As SecureString = SecureStringUtils.Create(TEST_PASSWORD)
        Using pwd2 As New PasswordHash(sstr, pwd1.Salt)
            Assert.AreEqual(pwd1, pwd2)
        End Using
        Using pwd2 As New PasswordHash(sstr)
            Assert.AreNotEqual(pwd1, pwd2)
        End Using
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys