I have a script that makes some registry changes to allow users to do things they normally shouldn't (i.e. use removable media). I would like a function that turns username + date into a One Day Password.
Example : jsmith + 6/28/2018 = JFT6QD
If the user enters the correct code, the script will continue to execute. If incorrect, display wah-wah-wah message.
Has anyone seen such a piece of code or can any expert provide some guidance or suggestions?
Generate ODP (one day password) generated from Username and Date
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Generate ODP (one day password) generated from Username and Date
I think I figured it out using the Get-StringHash script found here:
https://gallery.technet.microsoft.com/s ... h-aa843f71
$String = Get-StringHash "jsmith 6/28/2018" "SHA1"
$String = $String.substring(0,7)
Write-Host $String
ac1e7c1
https://gallery.technet.microsoft.com/s ... h-aa843f71
$String = Get-StringHash "jsmith 6/28/2018" "SHA1"
$String = $String.substring(0,7)
Write-Host $String
ac1e7c1
Re: Generate ODP (one day password) generated from Username and Date
Near final code..
Code Generator for Helpdesk:
User Script
Code Generator for Helpdesk:
Code: Select all
Function Get-StringHash([String]$String, $HashName = "MD5")
{
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String)) | %{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
$Username = Read-Host -Prompt "Please enter username in DOMAIN\username format:"
$Username = $Username.ToLower()
$String = ($Username) + (Get-Date -format "dd-MMM-yyyy")
$Hash = Get-StringHash $String
$Hash = $Hash.substring(5, 5)
$Hash
Code: Select all
Function Get-StringHash([String]$String, $HashName = "MD5")
{
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String)) | %{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
$Username = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$Username = $Username.ToLower()
$String = ($Username) + (Get-Date -format "dd-MMM-yyyy")
$Hash = Get-StringHash $String
$Hash = $Hash.substring(5, 5)
$Code = Read-Host -Prompt "Please enter access code:"
$Code = $code.ToLower()
if ($Hash -Match $Code) {
Write-Host "True!"
#Continue doing shtuff
}
else
{
Write-Host "Womp Womp Womp.. False!"
}