Clean up formatting and add comments to DynamicPassword.ahk
This commit is contained in:
+73
-27
@@ -1,45 +1,91 @@
|
|||||||
|
; ==============================================================================
|
||||||
|
; DynamicPassword.ahk
|
||||||
|
; Deterministic Password Generator
|
||||||
|
; ==============================================================================
|
||||||
|
; This script generates a unique, complex password based on a service name
|
||||||
|
; and a personal salt. The password is never stored and is generated on-the-fly.
|
||||||
|
; ==============================================================================
|
||||||
|
|
||||||
#NoEnv
|
#NoEnv
|
||||||
#SingleInstance force
|
#SingleInstance force
|
||||||
#Persistent
|
#Persistent
|
||||||
|
|
||||||
|
; --- Hotkeys ---
|
||||||
|
|
||||||
|
; WIN + F1: Generate a 32-character password
|
||||||
#F1::
|
#F1::
|
||||||
Password(32)
|
Password(32)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
; WIN + F2: Generate a 16-character password
|
||||||
#F2::
|
#F2::
|
||||||
Password(16)
|
Password(16)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
; --- Core Logic ---
|
||||||
|
|
||||||
Password(Length) {
|
Password(Length) {
|
||||||
InputBox, Service, Website/Service, Enter the name of the site:, , 200, 130
|
; Prompt for the website or service name (e.g., "gmail")
|
||||||
InputBox, Salt, Password Salt, Enter a salt password:, hide , 200, 130
|
InputBox, Service, Website/Service, Enter the name of the site:, , 200, 130
|
||||||
Hash := MD5(MD5(Service)Salt)MD5(MD5(Salt)Service)
|
if (ErrorLevel) ; User cancelled
|
||||||
Loop, %Length% {
|
return
|
||||||
Char := SubStr(Hash, A_Index*2-1, 2)
|
|
||||||
Char2Hex = 0x%Char%
|
; Prompt for the personal salt (a simple password only you know)
|
||||||
Hex := Chr(Round((Char2Hex + 0)/2.74)+33)
|
InputBox, Salt, Password Salt, Enter a salt password:, hide , 200, 130
|
||||||
Pwd := Pwd Hex
|
if (ErrorLevel) ; User cancelled
|
||||||
}
|
return
|
||||||
Clipboard:=Pwd
|
|
||||||
MouseGetPos x1, y1
|
; Generate a complex hash by combining MD5 of Service and Salt in a cross-pattern
|
||||||
ToolTip, Password copied to clipboard, %x1%, %y1%
|
; This creates a unique signature for the site/salt combination.
|
||||||
SetTimer, RemoveToolTip, 1000
|
Hash := MD5(MD5(Service) . Salt) . MD5(MD5(Salt) . Service)
|
||||||
Sleep, 1000
|
|
||||||
Reload
|
; Map the hash characters to a wider range of ASCII symbols
|
||||||
|
; to create a complex password.
|
||||||
|
Pwd := ""
|
||||||
|
Loop, %Length% {
|
||||||
|
; Extract 2 characters from the hash
|
||||||
|
Char := SubStr(Hash, A_Index * 2 - 1, 2)
|
||||||
|
Char2Hex := "0x" . Char
|
||||||
|
|
||||||
|
; Transform the hex value into a printable ASCII character (Range: 33-126)
|
||||||
|
; Logic: (HexValue / 2.74) + 33 maps 0-255 to roughly 33-126 range.
|
||||||
|
Hex := Chr(Round((Char2Hex + 0) / 2.74) + 33)
|
||||||
|
Pwd .= Hex
|
||||||
|
}
|
||||||
|
|
||||||
|
; Copy to clipboard and notify the user
|
||||||
|
Clipboard := Pwd
|
||||||
|
MouseGetPos, x1, y1
|
||||||
|
ToolTip, Password copied to clipboard, %x1%, %y1%
|
||||||
|
|
||||||
|
; Auto-hide the tooltip after 1 second
|
||||||
|
SetTimer, RemoveToolTip, 1000
|
||||||
|
Sleep, 1000
|
||||||
|
|
||||||
|
; Reload the script to clear variables from memory for extra security
|
||||||
|
Reload
|
||||||
}
|
}
|
||||||
|
|
||||||
MD5( ByRef V, L=0 ) {
|
; MD5 Hashing Function using Windows Crypto API (advapi32)
|
||||||
VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
|
MD5(ByRef V, L = 0) {
|
||||||
DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) )
|
VarSetCapacity(MD5_CTX, 104, 0)
|
||||||
DllCall( "advapi32\MD5Final", Str,MD5_CTX )
|
DllCall("advapi32\MD5Init", "Ptr", &MD5_CTX)
|
||||||
Loop % StrLen( Hex:="123456789ABCDEF0" )
|
DllCall("advapi32\MD5Update", "Ptr", &MD5_CTX, "Str", V, "UInt", L ? L : VarSetCapacity(V))
|
||||||
N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
|
DllCall("advapi32\MD5Final", "Ptr", &MD5_CTX)
|
||||||
Return MD5
|
|
||||||
|
Hex := "123456789ABCDEF0"
|
||||||
|
Loop 16 {
|
||||||
|
N := NumGet(MD5_CTX, 87 + A_Index, "UChar")
|
||||||
|
MD5 .= SubStr(Hex, N >> 4, 1) . SubStr(Hex, N & 15, 1)
|
||||||
|
}
|
||||||
|
Return MD5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; ToolTip Cleanup
|
||||||
RemoveToolTip:
|
RemoveToolTip:
|
||||||
SetTimer, RemoveToolTip, Off
|
SetTimer, RemoveToolTip, Off
|
||||||
ToolTip
|
ToolTip
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user