Login with username as date

Never tried this before, but I have a system where the login details need to be username as a date, such as 2022-11-16, each time i try this I get an unauthorised response, anyone got any idea why?

I have tried sending the username by itself, as a string, and as a formatDate(‘yyyy-MM-dd’), as well as a combination of the two, format date, then convert to string.

The date in the database is stored as DATE, and not as a string.
The Login Form Input, looks like this.

<input type="date" class="form-control" id="inp_username_date" name="username_date" aria-describedby="inp_username_date_help" placeholder="Pick a Date *" required="">

Only work around so far is if I alter the MariaDB DATE to a VARCHAR instead, but that is really not ideal for me.

How about formatDate(‘yyyy/MM/dd’)?

1 Like

Never thought of trying that one, but sadly still not working.

How about a generated column that is a string representation of the date column? Use the date where you need date, and use the varchar for login.

1 Like

Thanks Ken, I think thats the best solution for now, and hopefully the team can take a look to see if it can be improved upon so i can revert later.

or you can use a dummy field … combined with Kens solution

<form>

<input type="date" class="form-control" id="dummy_inp_username_date" name="dummy_username_date" aria-describedby="dummy_inp_username_date" placeholder="Pick a Date *" required=""> 

<input type="text" id="inp_username_date" value="your real field as hidden" name="username_date" />

</form>

<script>

var $mail = $("#inp_username_date");

$("#dummy_inp_username_date").keyup(function() {

$mail.val( this.value );

});

$("#dummy_inp_username_date").blur(function() {

$mail.val( this.value );

});

$("#dummy_inp_username_date").click(function() {

$mail.val( this.value );

});

</script>
1 Like

This seems to work out of the box?

I made a table with a username field, date type Date

To save having to write a form i hard coded a set value step to the value in the database, data type date

Then set the validator to:

Works as it should

image

Aslo working with a form input set to date

So strange, on you on Wappler 5.1.4 and is it a MariaDB 10.5.x database.

I just tried again, and i also tried using a setvalue for the username just like your screenshot, and neither are working, both give me an unauthorised response.

Paul, are you sure there are no 2 same (date/username) entries in your database, and the security provider just finds the other one and shows unauthorized as the password is different?

Hey, Teo, yes my database only has 1 row, and that one is just that date.

Brian, I disabled my login step, and changed it to a validate step, and i get the same results as you, showing it should be working, but as a login step, it does not do the same.

yes, 5.1.4

I am working on a local node testbed setup i use specifically for testing scenarios like this, its Wappler local server with SQLite

Example with date not in database, no error response

So are you saying the validate step works but the login step doesn’t?

Yes, validate works, but login not.

Yes, i am seeing same

1 Like

Glad its not just me doing something wrong, thanks for testing too Brian, appreciate it.

Clearly not many people have ever used a date as a username, its a strange idea, but for this use case it really does work best.

Gut feeling is that the login is treating the username as a string, not a date.

Need to delve into the login script i guess unless on of the team can answer this

1 Like

Not a .js expert BUT found this in auth.js


    login: async function(options) {
        const provider = await this.getAuthProvider(this.parseRequired(options.provider, 'string', 'auth.login: provider is required.'));
        const username = this.parseOptional(options.username, 'string', this.parse('{{$_POST.username}}'));
        const password = this.parseOptional(options.password, 'string', this.parse('{{$_POST.password}}'));
        const remember = this.parseOptional(options.remember, '*', this.parse('{{$_POST.remember}}'));

Note, username is treat as a string

1 Like

Ahh that makes sense then why it does not work, wonder if this is a George or Patrick fix, if the Wappler team feel this is even something that needs fixing I suppose, considering its not a very common practise.