nyk commited on
Commit
8a143d4
·
unverified ·
1 Parent(s): d4c6814

fix: use CSPRNG for password generation in install.ps1 (#424)

Browse files

Replace Get-Random (System.Random, clock-seeded) with RandomNumberGenerator in Get-RandomPassword to match the CSPRNG already used by Get-RandomHex.

Files changed (1) hide show
  1. install.ps1 +4 -1
install.ps1 CHANGED
@@ -68,7 +68,10 @@ function Test-Command { param([string]$Name) $null -ne (Get-Command $Name -Error
68
  function Get-RandomPassword {
69
  param([int]$Length = 24)
70
  $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
71
- -join (1..$Length | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })
 
 
 
72
  }
73
 
74
  function Get-RandomHex {
 
68
  function Get-RandomPassword {
69
  param([int]$Length = 24)
70
  $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
71
+ $rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
72
+ $bytes = New-Object byte[] $Length
73
+ $rng.GetBytes($bytes)
74
+ -join ($bytes | ForEach-Object { $chars[$_ % $chars.Length] })
75
  }
76
 
77
  function Get-RandomHex {