PDA

View Full Version : Password through text file


Mr.Said
01-30-2008, 03:01 PM
Hello every one.

actually we all - may be not- know how to create password, but could any one please tell me

how to make password through separate text file

like I have password " indigo" and wanna save it as text file - pass.txt - under system root or whereever. and my project will read the file

thanx in advanced for help.
Mr.Said

AudioSam
01-31-2008, 04:49 AM
Hi Mr.Said,

Create your test.txt file (put your password in the text file)
Place it in C:\\

Create Page 1 and Duplicate.

Put this On Preload of Page 1 Properties

-- Read the contents of a text file to a table.
tabText = TextFile.ReadToTable("C:\\test.txt");



Put this On Show of Page 1 Properties

--assume the user enters a bad password
correct_password = false;

-- the 'correct' password
real_passwords = tabText;

-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);

-- compare the user's password to the 'correct' password.
for j in real_passwords do
if real_passwords[j] == user_password then
correct_password = true;
Page.Jump("Page2")
end
end

--if the password was bad, exit
if not correct_password then
Application.Exit();
end



AudioSam

AudioSam
01-31-2008, 05:13 AM
Actually the block of code for Preload could go above
the code Page 1 On Show.

AudioSam

AudioSam
01-31-2008, 07:14 AM
Hi Mr.Said,



Create your test.txt file (put your password in the text file)
Place it in C:\\

Create Page 1
Put this On Show of Page 1 Properties



-- Read the contents of a text file to a table.
tabText = TextFile.ReadToTable("C:\\test.txt");
if tabText[2] == "RegistrationComplete" then
Application.ExitScript()
end

--assume the user enters a bad password
correct_password = false;
-- the 'correct' password
real_passwords = tabText;
-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);

-- compare the user's password to the 'correct' password.
for j in real_passwords do
if real_passwords[j] == user_password then
correct_password = true;

tabText = {""};
Table.Insert(tabText, 2, "RegistrationComplete");
TextFile.WriteFromTable("C:\\test.txt", tabText, true)
end
end

--if the password was bad, exit
if not correct_password then
Application.Exit();

end


No more changes....:huh
AudioSam

RizlaUK
01-31-2008, 10:40 AM
No more changes....

lol, just one more ;)

if you are going to store a password in a file then either the password or the file needs to be encrypted else hacking the pw will be like candy+baby!.....just my 2 pence

Hey Audio, i see you are getting it together with this coding lark, now you able to help others :yes

AudioSam
01-31-2008, 11:59 AM
Where do I start....
About encrypting....
I'll leave that to you guys to tell them how.
I tried to help with what Bruce had posted.
Man , I butchered that up in an all night fight.
The thing about trying is it makes me look like an idiot when I fail.
I only missed a whole nights sleep trying to figure it out.
All that just to make him mad... :D
Anyway, I am understanding some things a little better.
On this password file.
I took what Mr. Said to be so that once someone put in a password
they wouldn't have to keep putting it in.
In that case no one else would need a password because the App
would be open to anyone.
I see what your thoughts would be though.
Thanks for keeping me in line.
Now I have to dig into how to encrypt a file
while loosing 12 hours of sleep... :eek:

Later m8,
AudioSam

Mr.Said
01-31-2008, 01:44 PM
Hello guys.

I am really very thankful to you cause I didnt have anytime to try any code but I come now to see the great result.

thank you very much for such effort YOU did for me "AudioSam"

how much you would like to get for that ;);)

you really did what I want but also you could do the encrypting to have the final result

many many many thanks for you all overthere

Mr.Said
01-31-2008, 02:15 PM
Hello guys.


but the funn in this code is if you press on OK without putting a password then it ll go on without problem :huh :huh :huh :huh
it need to be solved right :rolleyes :rolleyes

it means no need to hack it, just enter

RizlaUK
01-31-2008, 02:43 PM
just need to check for no-text or cancel button


-- Read the contents of a text file to a table.
tabText = TextFile.ReadToTable("C:\\test.txt");
if tabText[2] ~= "RegistrationComplete" then
--assume the user enters a bad password
correct_password = false;
-- the 'correct' password
real_passwords = tabText;
-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);
-- check that some text was enterd and cancel wasent clicked
if user_password ~= "" and user_password ~= "CANCEL" then
-- compare the user's password to the 'correct' password.
for j in real_passwords do
if real_passwords[j] == user_password then
correct_password = true;
tabText = {""};
Table.Insert(tabText, 2, "RegistrationComplete");
TextFile.WriteFromTable("C:\\test.txt", tabText, true)
end
end
end
--if the password was bad, exit
if not correct_password then
Application.Exit();
end
end

^^ untested code

its the same as AudioSam's code just rearranged


I butchered that up in an all night fight.
The thing about trying is it makes me look like an idiot when I fail.

Dont be so hard on you, i shot myself in the foot loads when i first started giving help here, just made me think about what i was doing more and try to find the best solution to the problem

Mr.Said
01-31-2008, 03:33 PM
well I think now we won over OK button, but the questen is:

why the program needs to ask the password since it is saved in the file test.txt.

and if you try to delete the file see what ll happen, you could enter the project.

my sweet regards.

AudioSam
02-01-2008, 07:09 AM
I tried the delete the file and I see it does allow app to run.
I will look at that, I think it's an easy fix.

Are you wanting this so that a user has to enter the password
every time or only once and then the app will open from then on
with out password?

I am not nearly as good as many others in the forum
but I will try to help.

AudioSam

AudioSam
02-01-2008, 07:41 AM
Place your test.txt file in your Apps Docs Folder with
your password in the text file.

Same as earlier, Place this code in Page/On Show



File.Copy("AutoPlay\\Docs\\test.txt", "C:\\test.txt", false, false, false, true)
IFT = File.DoesExist("C:\\test.txt")
if IFT == false then
Dialog.Message("Error", "A Critical File has been removed, Please contact Vendor", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1)
Application.Exit()
else
end
-- Read the contents of a text file to a table.
tabText = TextFile.ReadToTable("C:\\test.txt");
if tabText[2] ~= "RegistrationComplete" then
--assume the user enters a bad password
correct_password = false;
-- the 'correct' password
real_passwords = tabText;
-- prompt the user to enter a password
user_password = Dialog.PasswordInput("Password", "Please enter the password: ", MB_ICONQUESTION);
-- check that some text was enterd and cancel wasent clicked
if user_password ~= "" and user_password ~= "CANCEL" then
-- compare the user's password to the 'correct' password.
for j in real_passwords do
if real_passwords[j] == user_password then
correct_password = true;
tabText = {""};
Table.Insert(tabText, 2, "RegistrationComplete");
TextFile.WriteFromTable("C:\\test.txt", tabText, true)
end
end
end
--if the password was bad, exit
if not correct_password then
Application.Exit();
end
end


There are different ways to do this.
If your setting it up to send the user a password
it would be different than this.
let us know.
AudioSam

Mr.Said
02-01-2008, 02:24 PM
actually I would like the app to lunch dirctlly without even putting password,just check if the text file has same password as it is saved inside the app.

no need to give any one password,just they play.
beside I wanna place the text file out of the app. in case it got lost there ll be no access to the text file, or no expectation where will it be!

thanks alot for such great help

AudioSam
02-01-2008, 02:43 PM
Would it work to just send them a password and once they enter it one
time they won't be asked again?
If that would work you don't really need to reference it outside of the App.
Just send an email or whatever with the password they would enter one time.
Let us know.
AudioSam
I see ya Rizla.... : )

RizlaUK
02-01-2008, 02:48 PM
Why not use Application.SaveValue to get rid of the text file altogether, and you really need to encrypt the password

Try This:

1st run it will ask for a master password for the app, if entered ok then it will encrypt it and save it to the registry and run the app.

2nd (or any run after the first) if will read the encrypted password from the registry and compare it to the one entered by the user, if it dosent match then exit the app

Pug in page preload or project startup

blnAllow = false
-- Get the encrypted password
cptPassword = Application.LoadValue("Your_Application_Name", "Password");-- ENTER YOUR APP NAME HERE
-- Check that the password exists
if cptPassword ~= "" then
-- Password dose exists so ask the user to enter access pass
strUserData = Dialog.Input("Enter Password", "Please enter your password:", "", MB_ICONQUESTION);
-- Check that a password was enterd
if strUserData ~= "" and strUserData ~= "CANCEL" then
-- Decrypt our saved password
uncptPassword = Crypto.BlowfishDecryptString(cptPassword, "trustno1withthispassword");-- ENTER YOUR ENCRYPTION PASSWORD HERE
-- Now check the user password to the saved password
if strUserData == uncptPassword then
-- Is a match so allow app to run
blnAllow=true
else
-- Was not a match so ask again
blnAllow=false
end
else
blnAllow=false
end
else
-- Password dose not exist
strUserData = Dialog.Input("Enter Password", "Please enter a master password you would like to use:", "", MB_ICONQUESTION);
-- Check that a password was enterd
if strUserData ~= "" and strUserData ~= "CANCEL" then
-- password was enterd so encrypt it
cptPassword = Crypto.BlowfishEncryptString(strUserData, "trustno1withthispassword", 0);-- ENTER YOUR ENCRYPTION PASSWORD HERE
-- Now save it and allow the app to run
Application.SaveValue("Your_Application_Name", "Password", cptPassword);-- ENTER YOUR APP NAME HERE
blnAllow=true
else
blnAllow=false
end
end

if blnAllow == false then
Application.Exit(0);
end

RizlaUK
02-01-2008, 02:51 PM
I see ya Rizla.... : )

lol..

actually I would like the app to lunch dirctlly without even putting password,just check if the text file has same password as it is saved inside the app.

So you want more like a CD Key or Registration System ??

AudioSam
02-01-2008, 03:01 PM
I overlooked a couple of entries.............
Works great.. : )
AudioSam

TimeSurfer
02-01-2008, 03:27 PM
this is nothing really special in fact i hastily slapped this code together so i know it could use some improvements. but it does work

all it does is encrypt passwords and save them to a file. and lets you retrieve them.

give it a try.

AudioSam
02-01-2008, 03:38 PM
I was working with what Rizla posted.
I'll give yours a try.
Rizla,
What you posted.
Am I right that Password is the Master Password
and the Encryted Password is what you would send out.

When I type in Password it will allow the app to run
and when I type in the encrypted password it will run.
Unless I have something wrong that would mean the Master Password would
be visible in the Registry.
I guess to explain it a little better, it seems that whatever the Key name is
the app is alllowing that as the password also.
Is that correct?

Thanks ,
AudioSam

TimeSurfer
02-01-2008, 03:41 PM
no problem Sam,

like i stated its nothing special lol but it works. allows you to encrypt a password using a key you provide and store it according to name. then you can simply retrieve and decode the password by name and key. pretty neat really.... makes use of tables to return info.

AudioSam
02-01-2008, 04:25 PM
I still have a lot to learn.
Everytime I think I'm getting better something
comes along that I have a hard time figuring out.
I had never messed with encryption untill now.
I have to figure this out.
I ran the app, I went thru it, now I just have to figure out
how to add the information to an app..
It works well though.. : )

Thank You,
AudioSam

P.S,
Rizla I got the PW app working right.
I had changed the Password areas in the code.
It works very well. :p

RizlaUK
02-01-2008, 05:42 PM
Rizla I got the PW app working right.
I had changed the Password areas in the code.

lol, you had me checking my code then, thinking "well that is strange"

Mr.Said
02-03-2008, 03:03 PM
thank YOU ALL for the help
but I dont wanna user to know that there is password in fact.
that is way I got the idea of text file, and when I finish of using the app I can easly delete the text file,no password and the app will never get open

I wanna app to check by itself the text file which has password, if it is correct open otherwise close it without any password to enter or not to mintion it.

thank you for your try.
cheers