Jump to content

Checking 2 inputs


Recommended Posts

Hi all,

I'm scripting a login system for my server.
In the registration process a new player must enter a valid and working email.
To ensure the player use his own email, the resource will send a mail with a "activation code".
Once the player received the email, he will find a activation code to activate his account.

So now i got the problem that the script keeps saying that the activation code is wrong.
I don't know what i did wrong but i'm sure the code from the mail and the code i filled in are correct.

I thing it's a little bug but i don't understand how i could possibly solve this -_-

 

Spoiler

        elseif (source == SendConCodeBtn) then
            if ((DGS:dgsGetText (emailBoxReg)) == (DGS:dgsGetText (emailConBoxReg))) then
                if not (DGS:dgsGetText (emailBoxReg) == "")  then
                    DGS:dgsSetEnabled (emailBoxReg, false)
                    DGS:dgsSetEnabled (emailConBoxReg, false)
                    DGS:dgsSetEnabled (SendConCodeBtn, false)
                    DGS:dgsSetEnabled (emailCodeBoxReg, true)
                    DGS:dgsSetEnabled (activateAccBtn, true)
                    local sendto = DGS:dgsGetText (emailBoxReg)
                    theCode = math.random (10000000, 99999999)
                    setElementData (getLocalPlayer(), "player.code", theCode)
                    triggerServerEvent ("sendEMail", resourceRoot, sendto, theCode)
                else 
                    errorWdn (14)
                end
            else 
                errorWdn (13)
            end
            actCodeBoxState = true
        elseif (source == activateAccBtn) then
            theCode = getElementData (getLocalPlayer(), "player.code")
            inputCode = DGS:dgsGetText (emailCodeBoxReg)
            if theCode == inputCode then
                DGS:dgsSetVisible (registerWdn, false)
                outputDebugString ("code work (got code) " ..(curCode))
                outputDebugString ("box " ..(inputCode))
            else
                outputDebugString ("wrong code ".. (curCode))
                outputDebugString ("box " ..(inputCode))
            end

 

 

Link to post
  • Moderators
3 minutes ago, Potato_Tomato420 said:

I thing it's a little bug but i don't understand how i could possibly solve this -_-

It is a bit strange that serverside does not validate the code. This even makes it even possible for other players to modify your code, if those players can inject Lua.


But about your problem, 1 of the 2 have to be incorrect:

iprint("theCode=", theCode, "\ninputCode=",inputCode)

Debug to figure out which one is broken.

Link to post
  • Moderators
21 minutes ago, Potato_Tomato420 said:

The debug does already shows both codes and seems to be ok.. but still

Convert both codes to a string. Maybe one is a number and one is a string.

if tostring(theCode) == tostring(inputCode) then

end

 

22 minutes ago, Potato_Tomato420 said:

Do i need to check the activation code serverside? That seems like a bad idea to me.

That is what people normally do for security reasons. Do what you want.

Link to post

Thx, adding tostring seams to work. :D

Still i don't get it why i need to add tostring to convert the numbers to a string.
The debug was showing both codes and the seems to be ok but still that didn't work.

But thx for the support! I almost got a headache because i could solve it xDD

Link to post
  • Moderators
1 hour ago, Potato_Tomato420 said:

The debug was showing both codes and the seems to be ok but still that didn't work.

That is the tricky part about strings and numbers, they are represents each other a lot, but at the core they are very different.

The console will indeed not show any difference between strings and numbers, that is also because everything inside of the debug console is already converted to a string. All string indications " "' ' [[ ]] are not included.

To debug that correctly, you can use the type function.

Edited by IIYAMA
Link to post

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...