Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,192 +0,0 @@
|
|||
with Ada.Numerics.Discrete_Random;
|
||||
with Ada.Strings.Fixed;
|
||||
with Ada.Command_Line;
|
||||
with Ada.Integer_Text_IO;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Mkpw is
|
||||
|
||||
procedure Put_Usage;
|
||||
procedure Parse_Command_Line (Success : out Boolean);
|
||||
function Create_Password (Length : in Positive;
|
||||
Safe : in Boolean)
|
||||
return String;
|
||||
|
||||
procedure Put_Usage is
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
Put_Line ("Usage: ");
|
||||
Put_Line (" mkpw help - Show this help text ");
|
||||
Put_Line (" mkpw [count <n>] [length <l>] [seed <s>] [safe] ");
|
||||
Put_Line (" count <n> - Number of passwords generated (default 4)");
|
||||
Put_Line (" length <l> - Password length (min 4) (default 4)");
|
||||
Put_Line (" seed <l> - Seed for random generator (default 0)");
|
||||
Put_Line (" safe - Do not use unsafe characters (0O1lIS52Z)");
|
||||
end Put_Usage;
|
||||
|
||||
Lower_Set : constant String := "abcdefghijklmnopqrstuvwxyz";
|
||||
Upper_Set : constant String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
Digit_Set : constant String := "0123456789";
|
||||
Spec_Set : constant String := "!""#$%&'()*+,-./:;<=>?@[]^_{|}~";
|
||||
Unsafe_Set : constant String := "0O1lI5S2Z";
|
||||
|
||||
Full_Set : constant String := Lower_Set & Upper_Set & Digit_Set & Spec_Set;
|
||||
subtype Full_Indices is Positive range Full_Set'Range;
|
||||
|
||||
package Full_Index_Generator is
|
||||
new Ada.Numerics.Discrete_Random (Full_Indices);
|
||||
|
||||
Index_Generator : Full_Index_Generator.Generator;
|
||||
|
||||
Config_Safe : Boolean := False;
|
||||
Config_Count : Natural := 4;
|
||||
Config_Length : Positive := 6;
|
||||
Config_Seed : Integer := 0;
|
||||
Config_Show_Help : Boolean := False;
|
||||
|
||||
procedure Parse_Command_Line (Success : out Boolean) is
|
||||
use Ada.Command_Line;
|
||||
Got_Safe, Got_Count : Boolean := False;
|
||||
Got_Length, Got_Seed : Boolean := False;
|
||||
Last : Positive;
|
||||
Index : Positive := 1;
|
||||
begin
|
||||
Success := False;
|
||||
if Argument_Count = 1 and then Argument (1) = "help" then
|
||||
Config_Show_Help := True;
|
||||
return;
|
||||
end if;
|
||||
|
||||
while Index <= Argument_Count loop
|
||||
if Ada.Command_Line.Argument (Index) = "safe" then
|
||||
if Got_Safe then
|
||||
return;
|
||||
end if;
|
||||
Got_Safe := True;
|
||||
Config_Safe := True;
|
||||
Index := Index + 1;
|
||||
elsif Argument (Index) = "count" then
|
||||
if Got_Count then
|
||||
return;
|
||||
end if;
|
||||
Got_Count := True;
|
||||
Ada.Integer_Text_IO.Get (Item => Config_Count,
|
||||
From => Argument (Index + 1),
|
||||
Last => Last);
|
||||
if Last /= Argument (Index + 1)'Last then
|
||||
return;
|
||||
end if;
|
||||
Index := Index + 2;
|
||||
elsif Argument (Index) = "length" then
|
||||
if Got_Length then
|
||||
return;
|
||||
end if;
|
||||
Got_Length := True;
|
||||
Ada.Integer_Text_IO.Get (Item => Config_Length,
|
||||
From => Argument (Index + 1),
|
||||
Last => Last);
|
||||
if Last /= Argument (Index + 1)'Last then
|
||||
return;
|
||||
end if;
|
||||
if Config_Length < 4 then
|
||||
return;
|
||||
end if;
|
||||
Index := Index + 2;
|
||||
elsif Argument (Index) = "seed" then
|
||||
if Got_Seed then
|
||||
return;
|
||||
end if;
|
||||
Got_Seed := True;
|
||||
Ada.Integer_Text_IO.Get (Item => Config_Seed,
|
||||
From => Argument (Index + 1),
|
||||
Last => Last);
|
||||
if Last /= Argument (Index + 1)'Last then
|
||||
return;
|
||||
end if;
|
||||
Index := Index + 2;
|
||||
else
|
||||
return;
|
||||
end if;
|
||||
end loop;
|
||||
Success := True;
|
||||
exception
|
||||
when Constraint_Error | Ada.Text_IO.Data_Error =>
|
||||
null;
|
||||
end Parse_Command_Line;
|
||||
|
||||
function Create_Password (Length : in Positive;
|
||||
Safe : in Boolean)
|
||||
return String
|
||||
is
|
||||
|
||||
function Get_Random (Safe : in Boolean)
|
||||
return Character;
|
||||
|
||||
function Get_Random (Safe : in Boolean)
|
||||
return Character
|
||||
is
|
||||
use Ada.Strings.Fixed;
|
||||
C : Character;
|
||||
begin
|
||||
loop
|
||||
C := Full_Set (Full_Index_Generator.Random (Index_Generator));
|
||||
if Safe then
|
||||
exit when Index (Source => Unsafe_Set, Pattern => "" & C) = 0;
|
||||
else
|
||||
exit;
|
||||
end if;
|
||||
end loop;
|
||||
return C;
|
||||
end Get_Random;
|
||||
|
||||
function Has_Four (Item : in String)
|
||||
return Boolean;
|
||||
|
||||
function Has_Four (Item : in String)
|
||||
return Boolean
|
||||
is
|
||||
use Ada.Strings.Fixed;
|
||||
Has_Upper, Has_Lower : Boolean := False;
|
||||
Has_Digit, Has_Spec : Boolean := False;
|
||||
begin
|
||||
for C of Item loop
|
||||
if Index (Upper_Set, "" & C) /= 0 then Has_Upper := True; end if;
|
||||
if Index (Lower_Set, "" & C) /= 0 then Has_Lower := True; end if;
|
||||
if Index (Digit_Set, "" & C) /= 0 then Has_Digit := True; end if;
|
||||
if Index (Spec_Set, "" & C) /= 0 then Has_Spec := True; end if;
|
||||
end loop;
|
||||
return Has_Upper and Has_Lower and Has_Digit and Has_Spec;
|
||||
end Has_Four;
|
||||
|
||||
Password : String (1 .. Length);
|
||||
begin
|
||||
loop
|
||||
for I in Password'Range loop
|
||||
Password (I) := Get_Random (Safe);
|
||||
end loop;
|
||||
exit when Has_Four (Password);
|
||||
end loop;
|
||||
return Password;
|
||||
end Create_Password;
|
||||
|
||||
Parse_Success : Boolean;
|
||||
begin
|
||||
|
||||
Parse_Command_Line (Parse_Success);
|
||||
|
||||
if Config_Show_Help or not Parse_Success then
|
||||
Put_Usage; return;
|
||||
end if;
|
||||
|
||||
if Config_Seed = 0 then
|
||||
Full_Index_Generator.Reset (Index_Generator);
|
||||
else
|
||||
Full_Index_Generator.Reset (Index_Generator, Config_Seed);
|
||||
end if;
|
||||
|
||||
for Count in 1 .. Config_Count loop
|
||||
Ada.Text_IO.Put_Line (Create_Password (Length => Config_Length,
|
||||
Safe => Config_Safe));
|
||||
end loop;
|
||||
|
||||
end Mkpw;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
lowercase: `a`..`z`
|
||||
uppercase: `A`..`Z`
|
||||
digits: `0`..`9`
|
||||
lowercase: 'a'..'z'
|
||||
uppercase: 'A'..'Z'
|
||||
digits: '0'..'9'
|
||||
other: map split "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~" => [to :char]
|
||||
|
||||
any: lowercase ++ uppercase ++ digits ++ other
|
||||
|
|
@ -11,7 +11,7 @@ generate: function [length][
|
|||
exit
|
||||
]
|
||||
|
||||
chars: new @[sample lowercase sample uppercase sample digits sample other]
|
||||
chars: @[sample lowercase sample uppercase sample digits sample other]
|
||||
while [length > size chars][
|
||||
'chars ++ sample any
|
||||
]
|
||||
|
|
@ -19,7 +19,7 @@ generate: function [length][
|
|||
join shuffle chars
|
||||
]
|
||||
|
||||
if 0 = size arg [
|
||||
if zero? arg [
|
||||
print {
|
||||
---------------------------------
|
||||
Arturo password generator
|
||||
|
|
|
|||
|
|
@ -1,119 +0,0 @@
|
|||
function New-RandomPassword
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generates one or more passwords.
|
||||
.DESCRIPTION
|
||||
Generates one or more passwords.
|
||||
.PARAMETER Length
|
||||
The password length (default = 8).
|
||||
.PARAMETER Count
|
||||
The number of passwords to generate.
|
||||
.PARAMETER Source
|
||||
An array of strings containing characters from which the password will be generated. The default is good for most uses.
|
||||
.PARAMETER ExcludeSimilar
|
||||
A switch which indicates that visually similar characters should be ignored.
|
||||
.EXAMPLE
|
||||
New-RandomPassword
|
||||
|
||||
Generates one password of the default length (8 characters).
|
||||
.EXAMPLE
|
||||
New-RandomPassword -Count 4
|
||||
|
||||
Generates four passwords each of the default length (8 characters).
|
||||
.EXAMPLE
|
||||
New-RandomPassword -Length 12 -Source abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789
|
||||
|
||||
Generates a password with a length of 12 containing at least one char from each string in Source
|
||||
.EXAMPLE
|
||||
New-RandomPassword -Count 4 -ExcludeSimilar
|
||||
|
||||
Generates four passwords each of the default length (8 characters) while excluding similar characters "Il1O05S2Z".
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[OutputType([string])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateRange(1,[Int]::MaxValue)]
|
||||
[Alias("l")]
|
||||
[int]
|
||||
$Length = 8,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateRange(1,[Int]::MaxValue)]
|
||||
[Alias("n","c")]
|
||||
[int]
|
||||
$Count = 1,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[Alias("s")]
|
||||
[string[]]
|
||||
$Source = @("abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "!\`"#$%&'()*+,-./:;<=>?@[]^_{|}~"),
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[Alias("x")]
|
||||
[switch]
|
||||
$ExcludeSimilar
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
[char[][]] $charArrays = $Source
|
||||
[char[]] $allChars = $charArrays | ForEach-Object {$_}
|
||||
[char[]] $similar = "Il1O05S2Z".ToCharArray()
|
||||
|
||||
$random = New-Object -TypeName System.Security.Cryptography.RNGCryptoServiceProvider
|
||||
|
||||
function Get-Seed
|
||||
{
|
||||
$bytes = New-Object -TypeName System.Byte[] -Argument 4
|
||||
$random.GetBytes($bytes)
|
||||
[BitConverter]::ToUInt32($bytes, 0)
|
||||
}
|
||||
|
||||
function Add-PasswordCharacter ([char[]]$From)
|
||||
{
|
||||
$key = Get-Seed
|
||||
|
||||
while ($password.ContainsKey($key))
|
||||
{
|
||||
$key = Get-Seed
|
||||
}
|
||||
|
||||
$index = (Get-Seed) % $From.Count
|
||||
|
||||
if ($ExcludeSimilar)
|
||||
{
|
||||
while ($From[$index] -in $similar)
|
||||
{
|
||||
$index = (Get-Seed) % $From.Count
|
||||
}
|
||||
}
|
||||
|
||||
$password.Add($key, $From[$index])
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
for ($i = 1;$i -le $Count; $i++)
|
||||
{
|
||||
[hashtable] $password = @{}
|
||||
|
||||
foreach ($array in $charArrays)
|
||||
{
|
||||
if($password.Count -lt $Length)
|
||||
{
|
||||
Add-PasswordCharacter -From $array # Append to $password
|
||||
}
|
||||
}
|
||||
|
||||
for ($j = $password.Count; $j -lt $Length; $j++)
|
||||
{
|
||||
Add-PasswordCharacter -From $allChars # Append to $password
|
||||
}
|
||||
|
||||
($password.GetEnumerator() | Select-Object -ExpandProperty Value) -join ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
New-RandomPassword -Length 12 -Count 4 -ExcludeSimilar
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
Set-Alias -Name nrp -Value New-RandomPassword -Description "Generates one or more passwords"
|
||||
|
||||
nrp -l 12 -n 4 -x
|
||||
Loading…
Add table
Add a link
Reference in a new issue