CSharpTest.Net
PasswordHash Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace : PasswordHash Class

Glossary Item Box

Creates a salted hash

Object Model

PasswordHash ClassSalt Class

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class PasswordHash 
   Inherits CSharpTest.Net.Bases.Comparable(Of PasswordHash)
C# 
public sealed class PasswordHash : CSharpTest.Net.Bases.Comparable<PasswordHash> 

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

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Bases.Equatable<T>
      CSharpTest.Net.Bases.Comparable<T>
         CSharpTest.Net.Crypto.PasswordHash

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys