Page 1 of 1

Generate ODP (one day password) generated from Username and Date

Posted: Thu Jun 28, 2018 7:54 am
by kerbob
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?

Re: Generate ODP (one day password) generated from Username and Date

Posted: Thu Jun 28, 2018 8:32 am
by kerbob
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

Re: Generate ODP (one day password) generated from Username and Date

Posted: Thu Jun 28, 2018 12:40 pm
by kerbob
Near final code..

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
User Script

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!"
}