Jump to content

Saving data


Recommended Posts

I wonder if this question has been posted or not, if so, please redirect me to the topic please?

Im rather new to autoit, and i dunno not to get data from a specified file.

What i am trying to do is that in a GUI window, i have an input where i type in a password. Then i click a button to encrypt and save the password in text file. That i can do.

But what i cant do is when the next time the program starts up, and it reaches that GUI, i cant make it check that file for the saved password, and input it in the GUI's input box.

Or to put it simple, how to get data from a certain text file and decrypt it?

Please, i really need help on this

Link to comment
Share on other sites

Yeah, i wanna get the data from a text file, decrypt it, then put the decrypted text in the input.

FileRead or FileReadLine doesnt work, it only gets the amount of characters/lines from the text file.

how do you get the data? like, what to put in GuiCtrlSetData("?")

If possible, can tell me how to retrieve only a specific line of data from teh text file? like the text file has:

line 1

line 2

line 3

and i wanna tak the "line 2" from the text file and leave the others alone.?

Link to comment
Share on other sites

Hi,One way to save data is to write an ini

Simple make a string with your Encrypted data

and save it example:

$Data=_StringEncrypt(1,GUICtrlRead($Input_1),$myPassword)
$msg=IniWrite($iniFile,"OPTIONS","Data",$Data)

when u wonna read this file

read the ini and make a decryption of that

example:

$Data=IniRead($iniFile,"OPTIONS","Data","")
$Data=_StringEncrypt(0,$Data,$myPassword)

You can also say (before saving)

$Data=_StringEncrypt(1,GUICtrlRead($Input_1),$myPassword)
Edited by Amen
Link to comment
Share on other sites

maybe something like this?

#include <GUIConstants.au3>
#include <String.au3>

;Generated with Form Designer preview
$Form1 = GUICreate("FooGui", 276, 60, 192, 125)
$Input1 = GUICtrlCreateInput("", 16, 16, 129, 21)
$Button1 = GUICtrlCreateButton("save", 150, 16, 60, 25)
$Button2 = GUICtrlCreateButton("load", 215, 16, 60, 25)
_getMyPasswd()
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button1
        IniWrite ( @ScriptDir&"\myini.ini", "FOO", "passwd", _StringEncrypt(1,GuiCtrlRead($Input1),"mypass"))
        GuiCtrlSetData($input1,"")
    Case $msg = $Button2
        _getMyPasswd()
    Case Else
    ;;;;;;;
    EndSelect
WEnd
Exit


func _getMyPasswd()
    if FileExists ( @ScriptDir&"\myini.ini" ) Then
        $a_KeyValues    = IniReadSection ( @ScriptDir&"\myini.ini", "FOO" )
        $decryptedValue = _StringEncrypt ( 0,$a_KeyValues[1][1] , "mypass" )
        GuiCtrlSetData($Input1,$decryptedValue)
    EndIf
EndFunc
Link to comment
Share on other sites

Something like this (untested) to read from a plain file

$Readline = "2"
$logfile = "textfile.txt"
$File = FileOpen ( $Logfile, 0)
$Linecount = 0
        While 1
           $line = FileReadLine($File)
            If @error = -1 Then ExitLoop
                      $linecount = $linecount + 1
            IF $Linecount = $Readline  then $StringtoDecrypt = $line
          Wend
FileClose ( $File )

;put your decrypt here $StringtoDecrypt holds line $Readline (2 in this case)
Link to comment
Share on other sites

Something like this (untested) to read from a plain file

[/code]
$Readline = "2"
$logfile = "textfile.txt"
$File = FileOpen ( $Logfile, 0)
$Linecount = 0
        While 1
           $line = FileReadLine($File)
            If @error = -1 Then ExitLoop
                      $linecount = $linecount + 1
            IF $Linecount = $Readline  then $StringtoDecrypt = $line
          Wend
FileClose ( $File )

;put your decrypt here $StringtoDecrypt holds line $Readline (2 in this case)
if you know the line in which is the String to decrypt you do not need a loop :P

$Readline = "2"
$logfile = "textfile.txt"
$File = FileOpen ( $Logfile, 0)
$line = FileReadLine($File,$Readline)
FileClose ( $File )
$decryptedValue = _StringEncrypt ( 0,$line , "mypass" )
Edited by jonk
Link to comment
Share on other sites

func _getMyPasswd()

if FileExists ( @ScriptDir&"\myini.ini" ) Then

$a_KeyValues = IniReadSection ( @ScriptDir&"\myini.ini", "FOO" )

$decryptedValue = _StringEncrypt ( 0,$a_KeyValues[1][1], "mypass" )

GuiCtrlSetData($Input1,$decryptedValue)

EndIf

EndFunc

What are the 2 [1] values for?
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...