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

data

Glossary Item Box

Creates the password from the given data and salt

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal data As String _
)
C# 
public Password( 
   string data
)

Parameters

data

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