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

Glossary Item Box

Stores an encrypted version of the supplied password in memory so that it can be provided as clear-text to external systems.

Object Model

Password ClassIPasswordDerivedBytes InterfaceIEncryptDecrypt InterfaceSalt Class

Syntax

Visual Basic (Declaration) 
Public Class Password 
   Inherits PasswordKey
   Implements IEncryptDecrypt 
C# 
public class Password : PasswordKey, IEncryptDecrypt  

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.Crypto.CryptoKey
      CSharpTest.Net.Crypto.PasswordKey
         CSharpTest.Net.Crypto.Password

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys