Inconsistant results for no reason

Hoping someone can assist me in working this one out, I have an app and it has a 2 factor authentication system i have built into it myself, the odd thing is sometimes it works exactly as expected and sometimes it just does not, and I can see no reason why i am getting different results.

  1. Registration Page, user enters in all their details and hits submit
    It writes all the details to a database row in a table, one of the fields in this row is email or sms another is needs validation

If the email or sms == 0 then the user wants SMS validation
If the email or sms == 1 then the user wants EMAIL validation
If the needs validation == 1 then the user has never completed the 2 factor auth
If the needs validation == 0 then the user does not need to do it.

So now the user has hit the submit button and it uses a dmx-on:success="browser1.goto('/login.aspx')" to take them to the login page where they need to enter the username and password they just supplied during registration.

So far this all works as expected, but this is when the trouble begins, I need to redirect the browser to the users profile when needs validation == 0 or redirect them to a validation page when needs validation == 1
Therefore if they are a returning user just logging in again there is no need for them to get a One Time Password, but if they are brand new, then they do.

Here are the server actions of my login script

The form code looks like this
<form is="dmx-serverconnect-form" id="scf1" method="post" action="dmxConnect/api/security/authenticated-fe-login.aspx" dmx-generator="bootstrap4" dmx-form-type="vertical" dmx-on:success="browser1.goto(scf1.data.return_action)">

The strange thing is that sometimes it does what I want and redirects to the correct page and other times it does not, and when i look at debugging it it seems that sometimes my database single query produces nul and sometimes it doesn’t, and im not talking about with different records, i mean same username and password, entered then refresh and try again, 3 work and 2 do not, or maybe 4 work and 1 does not.
It’s the strangest thing.

The query looks like this.

Could it be that the single query returns multiple rows? I have seen this once that if the query configured does not return exactly 1 row, it does not return the first row… it returns null instead.

Thanks Sid, I tried to double check and tested it a few different ways but it should never return more than one result, its filltering by the security provider identity and even looking at the table its accessing there is no duplicate data. So pretty strange.

I replicated the entire thing on php to test and that works flawlessly so I can only assume its an asp issue, but going to try work it out further so I can give a good bug report

As a last thing just out of interest it could also be me as server side variables with their name and global name and putting the same named variable in a then/else condition has always confused me. One day hopefully that concept will become more clear in my head