Skip to content

Commit 941566b

Browse files
author
Robin Stolpe
authored
Merge pull request #5 from rstolpe/dev
Made many changes
2 parents 414a7f5 + 426f3b3 commit 941566b

11 files changed

+287
-58
lines changed

.github/workflows/publish.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
name: Publish
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Publish
14+
env:
15+
PSGALLERY: ${{ secrets.PSGALLERY }}
16+
run: .\publish.ps1
17+
shell: pwsh
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
function New-RSRandomPassword {
3+
<#
4+
.SYNOPSIS
5+
Generate and returns a random password that includes numbers, letters and special characters.
6+
7+
.DESCRIPTION
8+
This module generates and returns a random password that contains lower and upper letters, numbers and special characters.
9+
It can either generate one with the default options that are 12 characters long and contains 3 special characters,
10+
or you can decide how long the password should be and how many special characters it should contain.
11+
12+
.PARAMETER Length
13+
Specify how many characters you want your password to be.
14+
Default is 12, shortest length is 6 and max length is 30.
15+
16+
.PARAMETER SpecialCharacters
17+
Specify how many special characters your password will has in it.
18+
Default is 3, shortest length is 1 and max length is 15.
19+
20+
.EXAMPLE
21+
New-RSRandomPassword
22+
# Returns a random password that are 12 characters long and contains 1 special character.
23+
24+
.EXAMPLE
25+
New-RSRandomPassword -Length 20 -SpecialCharacters 4
26+
# Returns a random password that are 20 characters long and contains 4 special character.
27+
28+
.NOTES
29+
Author: Robin Stolpe
30+
Mail: robin@stolpe.io
31+
Website: https://stolpe.io
32+
GitHub: https://github.com/rstolpe
33+
Twitter: https://twitter.com/rstolpes
34+
PSGallery: https://www.powershellgallery.com/profiles/rstolpe
35+
NuGet: https://www.nuget.org/profiles/rstolpe
36+
#>
37+
38+
[CmdletBinding()]
39+
param(
40+
[ValidateRange(6, 30)]
41+
[Parameter(Mandatory = $false, HelpMessage = "Specify how many character the password should contain")]
42+
[int]$Length = 12,
43+
[ValidateRange(1, 15)]
44+
[Parameter(Mandatory = $false, HelpMessage = "Specify how many special characters the password should conatin")]
45+
[int]$SpecialCharacters = 3
46+
)
47+
48+
$Character = 'abcdefghiklmnoprstuvwxyzABCDEFGHKLMNOPRSTUVWXYZ1234567890'
49+
$RandomCharacter = 1..$($Length - $SpecialCharacters) | ForEach-Object {
50+
Get-Random -Maximum $Character.length
51+
}
52+
53+
54+
$SpecialCharacter = '!@#$%^&.,_*()=+*?-'
55+
$RandomSpecialC = 1..$SpecialCharacters | ForEach-Object {
56+
Get-Random -Maximum $SpecialCharacter.length
57+
}
58+
59+
$private:ofs = ""
60+
$inputString = [String]$Character[$RandomCharacter]
61+
$inputString += [String]$SpecialCharacter[$RandomSpecialC]
62+
63+
$characterArray = $inputString.ToCharArray()
64+
$scrambledStringArray = $characterArray | Get-Random -Count $characterArray.Length
65+
$outputString = -join $scrambledStringArray
66+
return $outputString
67+
}

GenerateRandomPassword/GenerateRandomPassword.psd1

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
11
<#
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/>.
2+
MIT License
3+
4+
Copyright (C) 2023 Robin Stolpe.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
1423
#>
24+
1525
#
1626
# Module manifest for module 'GenerateRandomPassword'
1727
#
1828
# Generated by: Robin Stolpe
1929
#
20-
# Generated on: 2022-11-22
30+
# Generated on: 2023-01-21
2131
#
2232

2333
@{
2434

2535
# Script module or binary module file associated with this manifest.
26-
RootModule = '.\GenerateRandomPassword.psm1'
36+
RootModule = '.\GenerateRandomPassword.psm1'
2737

2838
# Version number of this module.
29-
ModuleVersion = '1.0'
39+
ModuleVersion = '1.0.1'
3040

3141
# Supported PSEditions
3242
# CompatiblePSEditions = @()
3343

3444
# ID used to uniquely identify this module
35-
GUID = 'f9318fbc-e3dd-45de-b12b-4b3224a107d7'
45+
GUID = 'f9318fbc-e3dd-45de-b12b-4b3224a107d7'
3646

3747
# Author of this module
38-
Author = 'Robin Stolpe'
48+
Author = 'Robin Stolpe'
3949

4050
# Company or vendor of this module
41-
CompanyName = 'Stolpe.io'
51+
CompanyName = 'Stolpe.io'
4252

4353
# Copyright statement for this module
44-
Copyright = '(c) 2022 Robin Stolpe. All rights reserved.'
54+
Copyright = '(c) 2023 Robin Stolpe. All rights reserved.'
4555

4656
# 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.'
57+
Description = 'Generate and returns a random password, you can choose how many characters and how many special characters it should contain.'
4858

4959
# Minimum version of the PowerShell engine required by this module
5060
PowerShellVersion = '5.1'
@@ -62,7 +72,7 @@
6272
# ClrVersion = ''
6373

6474
# Processor architecture (None, X86, Amd64) required by this module
65-
# ProcessorArchitecture = ''
75+
ProcessorArchitecture = ''
6676

6777
# Modules that must be imported into the global environment prior to importing this module
6878
# RequiredModules = @()
@@ -83,10 +93,10 @@
8393
# NestedModules = @()
8494

8595
# 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")
96+
FunctionsToExport = "New-RSRandomPassword"
8797

8898
# 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 = @()
99+
CmdletsToExport = @()
90100

91101
# Variables to export from this module
92102
VariablesToExport = '*'
@@ -109,22 +119,22 @@
109119
PSData = @{
110120

111121
# Tags applied to this module. These help with module discovery in online galleries.
112-
Tags = @("random-password", "generate-password", "sysadmin-tool", "support-tool", "it-tool", "random-password-generator", "generate-random-password")
122+
Tags = @("random-password", "generate-password", "sysadmin-tool", "support-tool", "it-tool", "random-password-generator", "generate-random-password")
113123

114124
# A URL to the license for this module.
115-
LicenseUri = 'https://github.com/rstolpe/GenerateRandomPassword/blob/main/LICENSE'
125+
LicenseUri = 'https://github.com/rstolpe/GenerateRandomPassword/blob/main/LICENSE'
116126

117127
# A URL to the main website for this project.
118-
ProjectUri = 'https://github.com/rstolpe/GenerateRandomPassword'
128+
ProjectUri = 'https://github.com/rstolpe/GenerateRandomPassword'
119129

120130
# A URL to an icon representing this module.
121-
# IconUri = ''
131+
# IconUri = ''
122132

123133
# ReleaseNotes of this module
124-
ReleaseNotes = 'https://github.com/rstolpe/GenerateRandomPassword/releases/tag/1.0'
134+
ReleaseNotes = 'https://github.com/rstolpe/GenerateRandomPassword/releases'
125135

126136
# Prerelease string of this module
127-
# Prerelease = ''
137+
Prerelease = ''
128138

129139
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
130140
RequireLicenseAcceptance = $false
@@ -137,10 +147,8 @@
137147
} # End of PrivateData hashtable
138148

139149
# HelpInfo URI of this module
140-
HelpInfoURI = 'https://github.com/rstolpe/GenerateRandomPassword/blob/main/README.md'
150+
# HelpInfoURI = ''
141151

142152
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
143153
# DefaultCommandPrefix = ''
144-
145154
}
146-

GenerateRandomPassword/GenerateRandomPassword.psm1

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
<#
2-
Copyright (C) 2022 Robin Stolpe <https://stolpe.io>
3-
This program is free software: you can redistribute it and/or modify
4-
it under the terms of the GNU General Public License as published by
5-
the Free Software Foundation, either version 3 of the License, or
6-
(at your option) any later version.
7-
This program is distributed in the hope that it will be useful,
8-
but WITHOUT ANY WARRANTY; without even the implied warranty of
9-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10-
GNU General Public License for more details.
11-
You should have received a copy of the GNU General Public License
12-
along with this program. If not, see <https://www.gnu.org/licenses/>.
13-
#>
2+
MIT License
3+
4+
Copyright (C) 2023 Robin Stolpe.
5+
<https://stolpe.io>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
1416
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
#>
1525
function New-RSRandomPassword {
1626
<#
1727
.SYNOPSIS
@@ -21,7 +31,7 @@ function New-RSRandomPassword {
2131
This module generates and returns a random password that contains lower and upper letters, numbers and special characters.
2232
It can either generate one with the default options that are 12 characters long and contains 3 special characters,
2333
or you can decide how long the password should be and how many special characters it should contain.
24-
34+
2535
.PARAMETER Length
2636
Specify how many characters you want your password to be.
2737
Default is 12, shortest length is 6 and max length is 30.
@@ -61,20 +71,20 @@ function New-RSRandomPassword {
6171
$Character = 'abcdefghiklmnoprstuvwxyzABCDEFGHKLMNOPRSTUVWXYZ1234567890'
6272
$RandomCharacter = 1..$($Length - $SpecialCharacters) | ForEach-Object {
6373
Get-Random -Maximum $Character.length
64-
}
74+
}
75+
6576

66-
6777
$SpecialCharacter = '!@#$%^&.,_*()=+*?-'
6878
$RandomSpecialC = 1..$SpecialCharacters | ForEach-Object {
6979
Get-Random -Maximum $SpecialCharacter.length
7080
}
7181

72-
$private:ofs = ""
82+
$private:ofs = ""
7383
$inputString = [String]$Character[$RandomCharacter]
7484
$inputString += [String]$SpecialCharacter[$RandomSpecialC]
7585

76-
$characterArray = $inputString.ToCharArray()
77-
$scrambledStringArray = $characterArray | Get-Random -Count $characterArray.Length
86+
$characterArray = $inputString.ToCharArray()
87+
$scrambledStringArray = $characterArray | Get-Random -Count $characterArray.Length
7888
$outputString = -join $scrambledStringArray
79-
return $outputString
80-
}
89+
return $outputString
90+
}

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Robin Stolpe
3+
Copyright (C) 2023 Robin Stolpe.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
# GenerateRandomPassword
2-
## SYNOPSIS
3-
This module let you generate a random password where you can choose length and how many special characters you want it to include.
1+
![GitHub](https://img.shields.io/github/license/rstolpe/GenerateRandomPassword?style=plastic)
2+
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/rstolpe/GenerateRandomPassword?sort=semver&style=plastic) ![Last release](https://img.shields.io/github/release-date/rstolpe/GenerateRandomPassword?style=plastic)
3+
![GitHub last commit](https://img.shields.io/github/last-commit/rstolpe/GenerateRandomPassword?style=plastic)
4+
![PSGallery downloads](https://img.shields.io/powershellgallery/dt/GenerateRandomPassword?style=plastic)
45

5-
## DESCRIPTION
6+
# GenerateRandomPassword
67
This module generates and returns a random password that contains lower and upper letters, numbers and special characters.
78
It can either generate one with the default options that are 12 characters long and contains 3 special characters,
89
or you can decide how long the password should be and how many special characters it should contain.
10+
I have added the result from PSScriptAnalyzer in [test folder](https://github.com/rstolpe/GenerateRandomPassword/tree/main/test)
11+
12+
# Links
13+
* [My PowerShell Collection](https://github.com/rstolpe/PSCollection)
14+
* [Webpage/Blog](https://www.stolpe.io)
15+
* [Twitter](https://twitter.com/rstolpes)
16+
* [LinkedIn](https://www.linkedin.com/in/rstolpe/)
17+
* [PowerShell Gallery](https://www.powershellgallery.com/profiles/rstolpe)
918

19+
# Help
20+
Below I have specified things that I think will help people with this module.
21+
You can also see the API for each function in the [help folder](https://github.com/rstolpe/GenerateRandomPassword/tree/main/help)
1022

1123
## Install
1224
Install for current user

0 commit comments

Comments
 (0)