Topic: Password Matching? (Need help with xLabel and Text Edit)
I have a label with a TextEditBox and I was wondering if there was a way to save or read the input that was entered in by the user so I could compare it with a password set beforehand.
Please see this forum thread
view the old Litestep.info page
You are not logged in. Please login or register.
LiteStep Community Forums → Theme Discussion → Password Matching? (Need help with xLabel and Text Edit)
I have a label with a TextEditBox and I was wondering if there was a way to save or read the input that was entered in by the user so I could compare it with a password set beforehand.
Yup, definitely.
You'll use a label event and !bang. It'll look something like...
YourLabelTextEditBoxEnterAction !TextEditBoxExecute YourLabel !SomeBang %[textinput]%
!SomeBang could be anything you've scripted and pass %[textinput]% as a variable for comparison.
I'm on mobile at the moment so can't get in to much mode detail right now. If you want to rip apart a theme that does this check my old FBL Dynamic 1.7.
Ok so say my label is called "Password" and the edit box is in the label "Password"
so the necessary items would look like this:
PasswordTextEditBoxEnterAction !TextEditBoxExecute Password !checkPass %[textinput]%
I'm using lua for the script:
function bang_checkPass()
if evar.Password == "%[textinput]%" then
exec('!hideLogin')
elseif evar.Password ~= "%[textinput]%" then
end
cfg_pass.Password = evar.Password
end
I know I'm doing something wrong because it's not working lol.
-----------
Also how would I be able to save or rather write "%[textinput]%" to a var?
Preferably using Lua.
If I try:
evar.Password = "%[textinput]%"
I get:
Password %[textinput]%
I'm on a computer now without Litestep, so I can't test stuff, but...
First, evar.Password = "%[textinput]%" would always just spit out %[textinput]% because you're assigning the string "%[textinput]%" to Password.
Ok, lets get the textinput in to the Password variable in your lua script. Try this instead, for the Label's event:
LabelNameTextEditBoxEnterAction !TextEditBoxExecute LabelName !SetVar Password %[textinput]%
Then, in your lua script, see if evar.Password is holding the inputted text. It should be. Then you can take it from there.
Note: I believe !SetVar is still a label !bang, so hopefully I got that right.
As for writing it to a text file (for reading/writing vars), I used to use xTextEdit.
Edit: I was just noticing in your function, your !checkPass bang in your lua script doesn't show it accepting the incoming variable... you need to do that, because that's what you want to evaluate. You can't parse "%[textinput]%" directly in your script. On the label`s event, %[textinput]% will be parsed to the actual value before sending it to your script. So, you can either do the event how I originally had it - accepting the incoming var to your function, or try it the other way I just mentioned. The first way would be best though. Passing variables to scripts opens up a lot of doorways in LiteStep scripting.
Edit: Here`s how it would look in mzscript...
;for the label...
PasswordTextEditBoxEnterAction !TextEditBoxExecute Password !checkPassword %[textinput]%
;for the script...
*Script bang !checkPassword
*Script exec !If ["%{args:1}" = "CurrentPassword"] [!SomeBangIfItIs][!SomeBangIfItIsNot]
*Script ~bang
*Script bang !SomeBangIfItIs
do stuff
*Script ~bang
*Script bang !SomeBangIfItIsNot
do stuff
*Script ~bang
Now if you can translate that in theory to lua, you`re set. "%{args:1}" would be holding the parsed variable from the %[textinput]%.
That`s about all the help I think I can be heh. Good luck.
where is %{args:1} stored? I'm guessing in memory?
Yup, variables are in memory unless you tell your script to write them out, to be reloaded at a later time (such as after a recycle).
In the first case:
My original plan was to write the password inputted from the textbox and then compare it with the preset password.
But when I used:
LabelNameTextEditBoxEnterAction !TextEditBoxExecute Password !SetVar Pw %[textinput]%
(Password is the label that holds the TextEditBox)
(Pw is the var that should hopefully hold the written Password)
The var was not written.
I also used !SetEvar but that didn't work either
--------------------------
In the second case when it would pass the variable:
So I then I need LUA to be able to read %{args:1} from memory thing is I wouldn't know how to do that.
So I found this in the documentation for Lua:
lslua.get_evar (name)
Get an evar's value in memory, not file. Returns a string, or nil if evar is not defined. Similar to what you expect $name$ would give.
Uses GetRCString().
Note: the preferred way to use this function is through the evar module.
lslua.get_line (name)
Get an evar's raw value in memory, not file. Returns a string, or nil if evar is not defined. Similar to get_evar but does not return first token.
Uses GetRCLine().
--------------------------
By the way thanks for all your help so far!
For a test, try
LabelNameTextEditBoxEnterAction !TextEditBoxExecute Password !Alert %[textinput]%
That should popup a box with the inputted text. That will at least tell you %[textinput]% is expanding to the proper variable.
Wish I was on a pc with LiteStep... This is all from my own memory, so be sure to check exact syntax in readmes.
I'm about to be offline until tomorrow, so best of luck.
Well I figured it out. Just thought I'd post it here.
local exec = lslua.exec
local get = lslua.get_line
local set = lslua.set_evar
local mb = lslua.message_box
......
function bang_check()
exec('!TextEditBoxExecute Password !SetEvar Pw %[textinput]%')
set(evar.Pw, evar.Pw)
if get(evar.realPw) == evar.Pw then
exec('!hideLogin')
elseif get(evar.realPw) ~= evar.Pw then
mb("Wrong Password", "")
end
end
"Pw" is the inputted password.
"realPw" is the preset password.
First "Pw" is set.
Then "Pw" is set again by LUA to equal itself otherwise it won't work (I don't know why).
Lastly it compares "Pw" with "realPw".
Thanks for the help xcal.
It'd be cool to get passing arguments working, too, though.
I think it should be as simple as...
function bang_check(incomingVar)
if incomingVar == evar.Pw then
exec('!hideLogin')
elseif incomingVar ~= evar.Pw then
mb("Wrong Password", "")
end
end
And the label would look like I originally had it...
PasswordTextEditBoxEnterAction !TextEditBoxExecute Password !check %[textinput]%
But anyway, you got it to work, and that's what's most important.
Glad you figured it out.
Well I got it to work like you suggested.
function Check(x)
if x == evar.realPw then
exec('!hideLogin')
elseif x ~= evar.realPw then
mb("Access Denied", "")
end
end
And I call the bang using:
!TextEditBoxExecute Password !LuaExec Check('%[textinput]%')
Thanks again xcal!
LiteStep Community Forums → Theme Discussion → Password Matching? (Need help with xLabel and Text Edit)
Powered by PunBB, supported by Informer Technologies, Inc.
The pun_posts_feed official extension is installed. Copyright © 2003–2010 PunBB.
Please see this forum thread
view the old Litestep.info page