Skip to content

Commit 3c49950

Browse files
author
Robin Stolpe
committed
update
1 parent 2d5153d commit 3c49950

File tree

3 files changed

+228
-1
lines changed

3 files changed

+228
-1
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<#
2+
Copyright (C) 2022 Robin Stolpe
3+
<https://stolpe.io>
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
You should have received a copy of the GNU General Public License
13+
along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
#>
15+
#
16+
# Module manifest for module 'GenerateRandomPassword'
17+
#
18+
# Generated by: Robin Stolpe
19+
#
20+
# Generated on: 2022-11-22
21+
#
22+
23+
@{
24+
25+
# Script module or binary module file associated with this manifest.
26+
RootModule = '.\GenerateRandomPassword.psm1'
27+
28+
# Version number of this module.
29+
ModuleVersion = '1.0'
30+
31+
# Supported PSEditions
32+
# CompatiblePSEditions = @()
33+
34+
# ID used to uniquely identify this module
35+
GUID = 'f9318fbc-e3dd-45de-b12b-4b3224a107d7'
36+
37+
# Author of this module
38+
Author = 'Robin Stolpe'
39+
40+
# Company or vendor of this module
41+
CompanyName = 'Stolpe.io'
42+
43+
# Copyright statement for this module
44+
Copyright = '(c) 2022 Robin Stolpe. All rights reserved.'
45+
46+
# Description of the functionality provided by this module
47+
Description = 'Generate and returns a random password, you can choose how many characters and how many special characters it should contain.'
48+
49+
# Minimum version of the PowerShell engine required by this module
50+
PowerShellVersion = '5.1'
51+
52+
# Name of the PowerShell host required by this module
53+
# PowerShellHostName = ''
54+
55+
# Minimum version of the PowerShell host required by this module
56+
# PowerShellHostVersion = ''
57+
58+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
59+
# DotNetFrameworkVersion = ''
60+
61+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
62+
# ClrVersion = ''
63+
64+
# Processor architecture (None, X86, Amd64) required by this module
65+
# ProcessorArchitecture = ''
66+
67+
# Modules that must be imported into the global environment prior to importing this module
68+
# RequiredModules = @()
69+
70+
# Assemblies that must be loaded prior to importing this module
71+
# RequiredAssemblies = @()
72+
73+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
74+
# ScriptsToProcess = @()
75+
76+
# Type files (.ps1xml) to be loaded when importing this module
77+
# TypesToProcess = @()
78+
79+
# Format files (.ps1xml) to be loaded when importing this module
80+
# FormatsToProcess = @()
81+
82+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
83+
# NestedModules = @()
84+
85+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
86+
FunctionsToExport = @("New-RSRandomPassword")
87+
88+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
89+
CmdletsToExport = @()
90+
91+
# Variables to export from this module
92+
VariablesToExport = '*'
93+
94+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
95+
AliasesToExport = @()
96+
97+
# DSC resources to export from this module
98+
# DscResourcesToExport = @()
99+
100+
# List of all modules packaged with this module
101+
# ModuleList = @()
102+
103+
# List of all files packaged with this module
104+
# FileList = @()
105+
106+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
107+
PrivateData = @{
108+
109+
PSData = @{
110+
111+
# Tags applied to this module. These help with module discovery in online galleries.
112+
Tags = @()
113+
114+
# A URL to the license for this module.
115+
LicenseUri = ''
116+
117+
# A URL to the main website for this project.
118+
ProjectUri = ''
119+
120+
# A URL to an icon representing this module.
121+
IconUri = ''
122+
123+
# ReleaseNotes of this module
124+
ReleaseNotes = ''
125+
126+
# Prerelease string of this module
127+
# Prerelease = ''
128+
129+
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
130+
RequireLicenseAcceptance = $false
131+
132+
# External dependent modules of this module
133+
# ExternalModuleDependencies = @()
134+
135+
} # End of PSData hashtable
136+
137+
} # End of PrivateData hashtable
138+
139+
# HelpInfo URI of this module
140+
HelpInfoURI = ''
141+
142+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
143+
# DefaultCommandPrefix = ''
144+
145+
}
146+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<#
2+
Copyright (C) 2022 Robin Stolpe
3+
<https://stolpe.io>
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
You should have received a copy of the GNU General Public License
13+
along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
#>
15+
16+
function New-RSRandomPassword {
17+
<#
18+
.SYNOPSIS
19+
Generate and returns a random password that includes numbers, letters and special characters.
20+
21+
.DESCRIPTION
22+
This module generates and returns a random password that contains lower and upper letters, numbers and special characters.
23+
It can either generate one with the default options that are 12 characters long and contains 3 special characters,
24+
or you can decide how long the password should be and how many special characters it should contain.
25+
26+
.PARAMETER Length
27+
Specify how many characters you want your password to be.
28+
Default is 12, shortest length is 6 and max length is 30.
29+
30+
.PARAMETER SpecialCharacters
31+
Specify how many special characters your password will has in it.
32+
Default is 3, shortest length is 1 and max length is 15.
33+
34+
.EXAMPLE
35+
New-RGRandomPassword
36+
# Returns a random password that are 12 characters long and contains 1 special character.
37+
38+
.EXAMPLE
39+
New-RGRandomPassword -Length 20 -SpecialCharacters 4
40+
# Returns a random password that are 20 characters long and contains 4 special character.
41+
42+
.NOTES
43+
Author: Robin Stolpe
44+
45+
Website: https://stolpe.io
46+
GitHub: https://github.com/rstolpe
47+
Twitter: https://twitter.com/rstolpes
48+
PSGallery: https://www.powershellgallery.com/profiles/rstolpe
49+
NuGet: https://www.nuget.org/profiles/rstolpe
50+
#>
51+
52+
[CmdletBinding()]
53+
param(
54+
[ValidateRange(6, 30)]
55+
[Parameter(Mandatory = $false)]
56+
[int]$Length = 12,
57+
[ValidateRange(1, 15)]
58+
[Parameter(Mandatory = $false)]
59+
[int]$SpecialCharacters = 3
60+
)
61+
62+
$Character = 'abcdefghiklmnoprstuvwxyzABCDEFGHKLMNOPRSTUVWXYZ1234567890'
63+
$RandomCharacter = 1..$($Length - $SpecialCharacters) | ForEach-Object {
64+
Get-Random -Maximum $Character.length
65+
}
66+
67+
68+
$SpecialCharacter = '!@#$%^&.,_*()=+*?-'
69+
$RandomSpecialC = 1..$SpecialCharacters | ForEach-Object {
70+
Get-Random -Maximum $SpecialCharacter.length
71+
}
72+
73+
$private:ofs = ""
74+
$inputString = [String]$Character[$RandomCharacter]
75+
$inputString += [String]$SpecialCharacter[$RandomSpecialC]
76+
77+
$characterArray = $inputString.ToCharArray()
78+
$scrambledStringArray = $characterArray | Get-Random -Count $characterArray.Length
79+
$outputString = -join $scrambledStringArray
80+
return $outputString
81+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GNU GENERAL PUBLIC LICENSE
22
Version 3, 29 June 2007
33

4-
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
4+
Copyright (C) 2022 Robin Stolpe. <https://stolpe.io/>
55
Everyone is permitted to copy and distribute verbatim copies
66
of this license document, but changing it is not allowed.
77

0 commit comments

Comments
 (0)