NET Password Generator
Generate Method
Example 



KellermanSoftware.NetPasswordGenerator Namespace > PasswordGenerator Class : Generate Method
Generate a password with the specified configuration
Syntax
'Declaration
 
Public Function Generate() As String
'Usage
 
Dim instance As PasswordGenerator
Dim value As String
 
value = instance.Generate()
public string Generate()
public:
String^ Generate(); 
Example
try
{
    //Licensed Mode
    //PasswordGenerator generator = new PasswordGenerator("User Name From Receipt", "License Key From Receipt");
 
    //Trial Mode
    PasswordGenerator generator = new PasswordGenerator();
 
    //Set the desired configuration
    generator.Config.MinNumbers = 1;
    generator.Config.MaxNumbers = 2;
    generator.Config.NumberPosition = Position.Center;
    generator.Config.ValidSpecialCharacters = "@#$";
    generator.Config.MinSpecialCharacters = 1;
    generator.Config.MaxSpecialCharacters = 1;
    generator.Config.SpecialCharacterPosition = Position.Center;
    generator.Config.MinUpperLetter = 1;
    generator.Config.MinLowerLetter = 1;
    generator.Config.MinWords = 2;
    generator.Config.MaxWords = 3;
    generator.Config.WordStyle = WordStyle.PopularWords;
    generator.Config.MinLength = 15;
    generator.Config.MaxLength = 20;
    generator.VerifyConfiguration();
 
    //Generate the password
    string password = generator.Generate();
    Console.WriteLine(password);
}
catch (PasswordConfigException pcex)
{
    Console.WriteLine("Password Configuration Exception: " + pcex.Message);
}
catch (PasswordException pex)
{
    Console.WriteLine("Password Exception: " + pex.Message);
}
catch (Exception ex)
{
    Console.WriteLine("Other Exception: " + ex.Message);
}
Try
    'Licensed Mode
    'PasswordGenerator generator = new PasswordGenerator("User Name From Receipt", "License Key From Receipt");
 
    'Trial Mode
    Dim generator As New PasswordGenerator()
 
    'Set the desired configuration
    generator.Config.MinNumbers = 1
    generator.Config.MaxNumbers = 2
    generator.Config.NumberPosition = Position.Center
    generator.Config.ValidSpecialCharacters = "@#$"
    generator.Config.MinSpecialCharacters = 1
    generator.Config.MaxSpecialCharacters = 1
    generator.Config.SpecialCharacterPosition = Position.Center
    generator.Config.MinUpperLetter = 1
    generator.Config.MinLowerLetter = 1
    generator.Config.MinWords = 2
    generator.Config.MaxWords = 3
    generator.Config.WordStyle = WordStyle.PopularWords
    generator.Config.MinLength = 15
    generator.Config.MaxLength = 20
    generator.VerifyConfiguration()
 
    'Generate the password
    Dim password As String = generator.Generate()
    Console.WriteLine(password)
Catch pcex As PasswordConfigException
    Console.WriteLine("Password Configuration Exception: " & pcex.Message)
Catch pex As PasswordException
    Console.WriteLine("Password Exception: " & pex.Message)
Catch ex As Exception
    Console.WriteLine("Other Exception: " & ex.Message)
End Try
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PasswordGenerator Class
PasswordGenerator Members