by machete143 · 9y ago · 0 comments
That's why I chose to make it explicit, and thus more likely to be caught in review if done.
export SYSTEM_SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo "SYSTEM_SECRET is $SYSTEM_SECRET" @(48..57 + 65..90 + 97..122) | Get-Random -Count 32 | ForEach-Object -Begin {$secret = ''} -Process {$secret += [char] $PSItem} -End {$env:SYSTEM_SECRET = $secret; Write-Host "SYSTEM_SECRET is $secret"}tr -dc A-Za-z0-9_ < /dev/urandom | head -c 32
?
And yes the "cat" is not necessary.
Of course, this runs the risk that a user will simply "salt" the sample you provide up to the necessary length, which makes the length of their secret effectively the difference between the minimum length and the sample length.