[solved]Stuck on a The input is not a valid Base-64 string error
Here is the full error message: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
The error shows up when I use my login endpoint when _signInManager.CheckPasswordSignInAsync manager is called.
Here are things I've tried:
1. Encoding loginDto.Password into a base64 string
2. Modifying thesigningkey, making it longer and shorter. Making sure it takes up 64 bytes.
The stack trace is too big for discord so it'll be in a comment
SOLUTION: The problem was that the password in the database wasn't encoded in base64
8 Replies
I'm confused. Nothing in that code appears to have anything to do with base64 strings?
I'm also confused for the same reason
Your code doesn't even have any mention of
CheckPasswordSignInAsync
, but from your question that seems to be important?Ah its in the middle, the whole line is:
_signInManager.CheckPasswordSignInAsync(user, loginDto.Password,false);
And what does it do, and where does the base64 string come from?
Its supposed to check that the password given is the correct password for a given user. Under the hood it uses CheckPasswordAsync for that.
I thought the string it was talking about was loginDto.Password but encoding that into base64 didn't change anything. This is what I did to convert it.
string encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(loginDto.Password));
I still don't have any information which lets me help you
What line throws the exception?
This one:
_signInManager.CheckPasswordSignInAsync(user, loginDto.Password,false);
Ah I'm starting to think the next place to look is the stack trace. I'll add it to the post.
Truncated Stack Trace:
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
at System.Convert.FromBase64String(String s)
at Microsoft.AspNetCore.Identity.PasswordHasher1.VerifyHashedPassword(TUser user, String hashedPassword, String providedPassword)
at Microsoft.AspNetCore.Identity.UserManager
1.VerifyPasswordAsync(IUserPasswordStore1 store, TUser user, String password)
at Microsoft.AspNetCore.Identity.UserManager
1.CheckPasswordAsync(TUser user, String password)
at Microsoft.AspNetCore.Identity.SignInManager`1.CheckPasswordSignInAsync(TUser user, String password, Boolean lockoutOnFailure)
at backendpv.Controllers.ManagerController.Login(LoginDto loginDto) in C:\Users\Kevin\source\repos\backendpv\backendpv\Controllers\ManagerController.cs:line 40