DaNy3LL 21 Posted December 1, 2014 Share Posted December 1, 2014 (edited) Hello guys, I tried to make a quest and I encountered a problem I need to check if a string entered by the player contains only letters and/or numbers (without symbols) I tried something like this , but it doesn't work ... when button or info begin say_title("Account Security:") say("This is used as a protection measure to prevent item") say("loss in case of your account being hacked/stolen.") say("") say_reward("If the protection is active you can't drop, sell, or exchange or use any item.") wait() say_title("Account Security:") say("Now please choose a password, so you can") say("manage this protection later.") say_orange("The password can only contain letters and numbers") say_orange("Your must use at least 6 characters, but no more") say_orange("than 12.") wait() say_title("Account Security:") say("Please enter a password :") local password = tostring(input()) if (validate_as_password(password) == true) then say("Your password is now "..password.."") set_as_password(password) send_letter("~Account Security") else say("Your password is either too long or too short or") say("contains symbols. Try again.") send_letter("~Account Security") return end end Those are the functions validate_as_password and set_as_password function set_as_password(password) local a = mysql_query("INSERT INTO account.account_security values ('"..pc.get_player_id().."', '"..password.."')") end function validate_as_password(password) if string.len(password) < 6 or string.len(password) > 12 then return false else if(password:match("%W")) then return false else return true end end end Here is a gif with the quest The function set_as_password works, but validate_as_password doesn't. The query runs, even if I enter symbols. When I enter a password which should be correct : When I enter a password which should be incorrect : Kind Regards, DaNy3LL Edited August 18, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 2, 2014 Author Share Posted December 2, 2014 BUMP Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 3, 2014 Author Share Posted December 3, 2014 BUMP Link to comment Share on other sites More sharing options...
Ken 904 Posted December 3, 2014 Share Posted December 3, 2014 If the player is pressed ESC, what is happening? Is closed or what? Best Regards Ellie Do not be sorry, be better. Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 3, 2014 Author Share Posted December 3, 2014 (edited) Yes, it closes and it seems like set_as_password(password) it's executing even if I press ESC Edited August 18, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Developer PACI 924 Posted December 3, 2014 Developer Share Posted December 3, 2014 Try with this: function validate_as_password(pw) return (string.len(pw) >= 6 and string.len(pw) <= 12) and (string.match(pw, "%W") == nil) end 1 when you return 0 and server doesn't boot: Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 3, 2014 Author Share Posted December 3, 2014 Thanks PACI. The check for invalid symbols works now, but when I enter a correct password (only letters and digits), nothing happens Link to comment Share on other sites More sharing options...
Denis 1474 Posted December 3, 2014 Share Posted December 3, 2014 This should work: when button or info begin say_title("Account Security:") say("This is used as a protection measure to prevent item") say("loss in case of your account being hacked/stolen.") say("") say_reward("If the protection is active you can't drop, sell, or exchange or use any item.") wait() say_title("Account Security:") say("Now please choose a password, so you can") say("manage this protection later.") say_orange("The password can only contain letters and numbers") say_orange("Your must use at least 6 characters, but no more") say_orange("than 12.") wait() say_title("Account Security:") say("Please enter a password :") local password = tostring(input()) if (string.len(password) >= 6 and string.len(password) <= 12) and (string.match(password, "%W") == nil) then say("Your password is now "..password.."") mysql_query("INSERT INTO account.account_security values ('"..pc.get_player_id().."', '"..password.."')") send_letter("~Account Security") else say("Your password is either too long or too short or") say("contains symbols. Try again.") send_letter("~Account Security") return end end Link to comment Share on other sites More sharing options...
Developer PACI 924 Posted December 3, 2014 Developer Share Posted December 3, 2014 Actually it wouldn't Denis, 'cause here: if (string.len(pw) >= 6 and string.len(pw) <= 12) and (string.match(pw, "%W") == nil) then pw wasn't declared, and you want to check the password variable content, so instead of pw it must be password. Also, maybe I'm wrong, but some special characters (e.g: say("~smth~")) don't work, so I guess you might add a space at the beginning of your send_letter(). Anyway, you should check what your syserr says. 1 when you return 0 and server doesn't boot: Link to comment Share on other sites More sharing options...
Denis 1474 Posted December 3, 2014 Share Posted December 3, 2014 Actually it wouldn't Denis, 'cause here: if (string.len(pw) >= 6 and string.len(pw) <= 12) and (string.match(pw, "%W") == nil) then pw wasn't declared, and you want to check the password variable content, so instead of pw it must be password. Also, maybe I'm wrong, but some special characters (e.g: say("~smth~")) don't work, so I guess you might add a space at the beginning of your send_letter(). Anyway, you should check what your syserr says. Yes I forgot to change the variable, thanks. Link to comment Share on other sites More sharing options...
DaNy3LL 21 Posted December 3, 2014 Author Share Posted December 3, 2014 In syserr I had RunState: LUA_ERROR: locale/uk/quest/questlib.lua:2053: attempt to call field `match' (a nil value) And I modified string.match to string.find and now works function validate_as_password(pw) return (string.len(pw) >= 6 and string.len(pw) <= 12) and (string.find(pw, "%W") == nil) end Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now