Hi everyone,
I had designed a normal login page where Username and Password are checked from a share point list. But now I wanted to add an option of Login-In using One Time Password. So for that I added a new button on the login screen named 'Login with OTP' like:

Note: When any user uses the normal login (without OTP), a check is done to see if the user has filled the additional details or not (along with checking the credentials), so similarly when user selects the Login with OTP I want to perform a similar check (after user gets the OTP, they enter it it should first check if the additional details are filled or not. If they are not then navigate to Additional Details page-> then Home screen (after all the fields in additional page is filled); else if the user has already filled the additional details then navigate them to Home screen (after entering the OTP)
So for the above flow I did use the following expression:
On Send OTP button (on OTPLogin screen):

The above expression is working fine, I am able to get the OTP. But there is one issue which I thought as I am generating the number using random(), in some cases it might generate a number 0.009876612 and when it is multiplied by 10000 and applying RoundDown, output will be 98, here the length of the OTP will be 2 instead of 4 😕 this was one minor issue.
Like this:

The second issue is:

The above expression is on 2nd button (which is Login: that user clicks on after entering the OTP), here after the user enters the OTP, as I had mentioned earlier I want to perform a check if the additional details are filled or not for which I have already created a SharePoint list named AdditionalDetails (In power Apps it is named as AdditionalDetails_1).
Example: Assume a user Jimmy who has already filled the additional details and he opts for Login with OTP option-> Enters the official email and gets the OTP -> Enters the OTP -> He should be navigated to Home screen not AdditionalDetails page (as details are already filled in)
But on Login button On-Select when a user enters the correct OTP it is navigating to Home screen but also displaying the notification message: The OTP you entered is incorrect & the Login with OTP screen was not getting reset (the text inputs for OTP was visible which should be only be visible after user enters email and click on Get OTP button)
The OTP TextInput and the login button will only be visible once user enters an email id and clicks on Generate OTP button, so for the textInput (to enter OTP) and the Login button I have used a variable which is set to True only when Generate OTP is clicked which is:


For reference:
Login Details (SharePoint List):

AdditionalDetails (ShatrePoint List):

The 3rd requirement that I had was: If a user opts for Login with OTP option and when they enter the email, an OTP should only be sent to the user email id if and only if they are registered in the application (here the data must be present in Login list: which has their credentials) if they are not registered in the application then a message should be shown please register first to login
So if anyone can help me with these requirements, it would be helpful (as 50% part is implemented) only some of the test case scenarios that I thought of I have mentioned here and if you feel any updates would be helpful (in the expression) do share them as well.
Also there is one query that I have posted on Forum 2 weeks back, so if you guys can have a look at it, it would be quite helpful as well:
Block user after entering invalid details after few wrong attempts
If you have some time please have a look at this: @RezaDorrani
Regards,
Sidhant