StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 function: auto fill username and password
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

breakcore

Russia
74 Posts

Posted - 02/26/2013 :  07:30:00  Show Profile  Reply with Quote
Hi, Rob.
Hi, Everione.

I find this function very useful.

What it does:
Automatically fills in the username and/or password data from a file which contains that data.
First it gets the active window title and searches for the match in the "data file".
1) If there is only one match then it immediately fills in username and password assigned to that window title.
2) If there is several matches, it pops up a drop down list dialog to choose desired account (only from those accounts which are assigned to the current window title). And then fills in the chosen account data.
3) If there is no match it pops up a drop-down list with all accounts to choose from. And then fills in the chosen account data.

Syntax for the data file:
web page/app name<TAB(s)>username<TAB(s)>password<TAB(s)>[|window title]<TAB(s)>[comments]
web page/app name 2<TAB(s)>username 2<TAB(s)>password 2<TAB(s)>[|window title 2]<TAB(s)>[comments 2]
----
----
"window title" and "comments" are optional. If you specify "window title" you must put a "|" character before it. You don't have to specify full title of window, just a part that distinguishes it from another window titles.
Note: Google chrome's window title is the same as the title of currently active tab.

Usage:
auto_fill(1) --to fill in username and password
auto_fill(2) --to fill in only password

Function
function auto_fill(af_mode)
	current_window_title=acGetWindowTitle(acGetForegroundWindow(),nil,nil)

	--local af_file_r=io.open("D:\\passwords.txt", "r")
	--af_file=af_file_r:read("*a")
	--af_file_r:close()
	--i keep my passwords right in the script file, if you want to keep them on a 
	--separate file use the three preceding lines above and change a file path
	af_file=
[[
strokesplus.com		username_1		password_1	|StrokesPlus		account email name@gmail.com
ebay.com		username_2		password_2	[|window title_2]	[comments]
skype			username_3		password_3	[|window title_3]	[comments]
name_4			username_4		password_4	[|window title_4]	[comments]
---
---
---

]]	
	total_lines=# af_file:gsub("[^\n]","")
	af_name={} af_username={} af_password={} af_window_title={} af_dialog=0 k=0 af_list=''
	for i=1,total_lines do
		current_line=string.sub(af_file,k+1,string.find(af_file,"\n",k+1))
		af_name[i]=string.gsub(current_line,"([^\t]+)\t+[^\t]+\t+[^\t]+\t*.*\n","%1")
		af_username[i]=string.gsub(current_line,"[^\t]+\t+([^\t]+)\t+[^\t]+\t*.*\n","%1")
		af_password[i]=string.gsub(current_line,"[^\t]+\t+[^\t]+\t+([^\t]+)\t*.*\n","%1")
		if string.gsub(current_line,"[^\t]+\t+[^\t]+\t+[^\t]+\t*(.).*\n","%1")=='|' then --If window title specified
			af_window_title[i]=string.gsub(current_line,"[^\t]+\t+[^\t]+\t+[^\t]+\t*|([^\t]+).*\n","%1")
		else
			af_window_title[i]="0"
		end
		k=string.find (af_file, "\n",k+1)
	end
	for i=1,total_lines do
		if string.find(current_window_title,af_window_title[i]) then
			af_dialog=1			--there is only one account assigned to this window/page title
			af_dialog_1_line=i
			for j=i+1,total_lines do
				if af_name[j]==af_name[i] then
					af_dialog=2	--there is several accounts assigned to this window/page title
					af_dialog_2_line=j
					af_dialog_2_site=af_name[i]
					break
				end
			end
			break
		end
	end	
	--acMessageBox(af_dialog,'af_dialog',nil)
	if af_dialog==0 then
		for i=1,total_lines do
			af_list=af_list..af_name[i]..'   '..af_username[i]..'|||'
		end
	elseif af_dialog==1 then
		username_line=af_username[af_dialog_1_line] 
		password_line=af_password[af_dialog_1_line] 
	elseif af_dialog==2 then
		for i=af_dialog_2_line-1,total_lines do
			if af_name[i]==af_dialog_2_site then
				af_list=af_list..af_name[i]..'   '..af_username[i]..'|||'
			end
		end
	end
	if af_dialog==0 or af_dialog==2 then
		choise=acInputBox("Title","Label",af_list,"|||")
		if choise~='' then 
			for i=1,total_lines do 
				if choise==af_name[i]..'   '..af_username[i] then 
					username_line=af_username[i] 
					password_line=af_password[i] 
					break
				end
			end 
		end
	end		
	--acMessageBox(username_line,'username_line',nil)
	--acMessageBox(password_line,'password_line',nil)
	if choise~='' then 
		acDelay(300)
		if af_mode==1 then 
			acSetClipboardText(username_line) acSendKeys("^v{Delay 100}{TAB}{Delay 200}^a")  acDelay(200) 
		end
		acSetClipboardText(password_line) acSendKeys("^v{Delay 200}{ENTER}")
	end
end


Any correction/optimization of the function would be appreciated
Sorry for my English if I made mistakes.

Edited by - breakcore on 02/26/2013 10:18:29

Rob

USA
2573 Posts

Posted - 02/26/2013 :  09:07:31  Show Profile  Visit Rob's Homepage  Reply with Quote
As always, breakcore, you impress with your ingenuity and code skills :-)
Go to Top of Page

breakcore

Russia
74 Posts

Posted - 02/26/2013 :  09:35:50  Show Profile  Reply with Quote
Thanks :)
The function actually still raw. I know, the code isn't easy to read/modify, even for me, but it works)
I'll post some updates, hopefully.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000