Sign in to follow this  
Followers 0
ChaosUltima

Saving data

11 posts in this topic

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

Share this post


Link to post
Share on other sites



wait, do you want to Get the text from the .txt file, and decrypt it THEN place the decrypted txt into the input box?

you can look in the help file for GUIctrlsetdata() and filereadline or iniread.


[size=20]My File Upload[/size]Register at my site and upload.

Share this post


Link to post
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.?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Great! It works! Thanks guys!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

What are the 2 [1] values for?

[sectionName]

Key=Value

$a_KeyValues[1][1] -> 1st Key in the Section

$a_KeyValues[1][1] -> 1st Value in the Section

The number of elements returned will be in $result[0][0].

Share this post


Link to post
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
Sign in to follow this  
Followers 0