How can I set a password for Visio files? -
i want put password on files no 1 can open without permission
it appears short answer not unless have password protection zip files.
you can test vba code , play visibility. won't guarantee security of document because visio doesn't have flexibility save macro-enabled drawing... limiting ability secure vba.
you pique confusion of undesired user reading/viewing having of pages hidden... security obscurity if will.... unless enable macros, can still ideally want document why should use encrypted zip software , password protect document way.
anyway... if you're still game crazy experiment tried...
enabled developer view. go view code. here's how works... first need generate password hash. once password hash created... delete entire
- copy main sub, temporary sub, , core subs , functions below "thisdocument" object in developer > view code page
- set password entering password in place of "mypassword" in genmypwd sub. can execute leaving curser in text of sub , clicking "run" button @ top of microsoft visual basic applications menu.
once see pop-up, press ctrl+v , paste content notepad. you'll effect.
--------------------------- password hash --------------------------- 78f56c460a6ca4b15554e5fe5469aa036fb21efa7151e991d6f9a9fda4548f79 --------------------------- ok ---------------------------
once have hash, set variable in private own unique hash value.
mypassword = "78f56c460a6ca4b15554e5fe5469aa036fb21efa7151e991d6f9a9fda4548f79"
one caveat though, you'll have create button hidepages script... or create key-capture event hotkey combination , use add additional vba code save, hidepages, , close visio.
main sub capture open document event. - before set variable
private sub document_documentopened(byval doc ivdocument) unauthenticated = true mypassword = "" while unauthenticated 'add number of tries tries = tries + 1 'prompt password trypassword = inputbox("enter password", "password required!") 'hash password attempt , compare current hash if sha256hash(trypassword) = mypassword 'escape loop unauthenticated = false call showpages else if ((tries > 2) , (unauthenticated = true)) killvisio end if loop end sub
main sub after set variable
private sub document_documentopened(byval doc ivdocument) unauthenticated = true mypassword = "6da6f219dac977da75f2f2894f33abad5052af2a60ae9219af0e302eddd5bbc4" while unauthenticated 'add number of tries tries = tries + 1 'prompt password trypassword = inputbox("enter password", "password required!") 'hash password attempt , compare current hash if sha256hash(trypassword) = mypassword 'escape loop unauthenticated = false call showpages else if ((tries > 2) , (unauthenticated = true)) killvisio end if loop end sub
additional required subs , functions
sub killvisio() set wshshell = createobject("wscript.shell") strcommand = "c:\windows\system32\taskkill /im visio.exe -f" wshshell.run ("cmd /c " & strcommand) end sub sub genmypwd() msgbox sha256hash("p@ssw0rd"), vbexclamation, "your password hash" end sub sub showpages() set vpages = thisdocument.pages = 1 vpages.count set visibility = vpages(i).pagesheet.cellsu("uivisibility") if visibility = 1 visibility.formulau = 0 end if next end sub sub hidepages() set vpages = thisdocument.pages = 1 vpages.count set visibility = vpages(i).pagesheet.cellsu("uivisibility") if visibility = 0 visibility.formulau = 1 end if next end sub function sha256hash(str) dim b() byte b = str sha256hash = bytestohex(sha256hashbytes(b)) end function function md5hashbytes(abytes) set objsha256 = createobject("system.security.cryptography.md5cryptoserviceprovider") s = objsha256.initialize() md5hashbytes = objsha256.computehash_2((abytes)) end function function sha256hashbytes(abytes) 'set objsha256 = createobject("system.security.cryptography.md5cryptoserviceprovider") set objsha256 = createobject("system.security.cryptography.sha256managed") objsha256 s = .initialize() sha256hashbytes = .computehash_2((abytes)) end end function function stringtoutfbytes(astring) set utf8 = createobject("system.text.utf8encoding") stringtoutfbytes = utf8.getbytes_4(astring) end function function bytestohex(abytes) x = 1 lenb(abytes) hexstr = hex(ascb(midb((abytes), x, 1))) if len(hexstr) = 1 hexstr = "0" & hexstr bytestohex = bytestohex & hexstr next end function
Comments
Post a Comment