Achilles Posted September 8, 2009 Share Posted September 8, 2009 (edited) For privacy, I have sometimes wanted to password protect an individual file. I didn't find an easy way so I made an easy way. Each .au3 script is essentially a .txt script. What happens is, you create a password on the first run. Then it open a very very basic text editor. When done, anything you wrote will be appended to the end of the file in an encrypted format. Next time you start up, enter your password and you data will be there. NOTE: Like I said, each .au3 file is essentially it's own file. If you want to make a new one, either copy one you already have and either remember the password or remove all the commented code at the bottom of the file. *** If you enter the password wrong once, you will never be able to see your data again*** (working to fix that) expandcollapse popup#Include <File.au3> #include <String.au3> Global Const $PATH = @ScriptFullPath Global Const $ENCRYPT_LEVEL = 1 Global $maxLines = _FileCountLines($PATH) Global $passCrypt $firstTime = _CheckFirst() If $firstTime then $passCrypt = InputBox('Vault', 'Welcome to Vault. Please create a password.', '', '*', 300, 140) If $passCrypt = '' then Exit $text = '' Else $passCrypt = InputBox('Vault', 'Welcome to Vault. Please enter your password.', '', '*', 300, 140) If $passCrypt = '' then Exit $text = '' $file = FileOpen($path, 0) $index = $maxLines $temp = StringStripWS(FileReadLine($file, $index) , 8) While StringLeft($temp, 1) = ';' $text = _StringEncrypt(0, StringTrimLeft($temp, 1), $passCrypt, $ENCRYPT_LEVEL) & @CRLF & $text $index -= 1 $temp = StringStripWS(FileReadLine($file, $index) , 8) WEnd FileClose($file) EndIf GUICreate('Vault', 500, 400) $hEdit = GUICtrlCreateEdit($text, 5, 5, 490, 390) GUISetState() Do Until GuiGetMsg() = -3 $file = FileOpen($path, 0) $origText = '' $indexFor = 1 $temp = FileReadLine($file, $indexFor) While StringLeft($temp, 1) <> ';' and $indexFor <= $maxLines $origText &= $temp & @CRLF $indexFor += 1 $temp = FileReadLine($file, $indexFor) WEnd FileClose($file) $file = FileOpen($path, 2) FileWrite($file, $origText) FileWrite($file, @CRLF) $editText = GUICtrlRead($hEdit) $array = StringSplit($editText, @CRLF) For $i = 1 to $array[0] $temp = _StringEncrypt(1, $array[$i], $passCrypt, $ENCRYPT_LEVEL) FileWriteLine($file, ';' & $temp) Next Func _CheckFirst() $file = FileOpen($PATH, 0) For $i = $maxLines to 0 Step -1 $temp = StringStripWs(FileReadLine($file, $i), 8) If StringLen($temp > 0) then FileClose($file) Return Not (StringLeft($temp, 1) = ';') EndIf Next EndFunc Edited September 8, 2009 by Achilles My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Adamrv1 Posted September 8, 2009 Share Posted September 8, 2009 This is a good start, but it still needs some work. When you update it, please let me know. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now