[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.
[HttpPost("login")]
public async Task<IActionResult> Login(LoginDto loginDto)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);

var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Email == loginDto.Email);

if (user == null)
return Unauthorized("Invalid Email");


var result = await _signInManager.CheckPasswordSignInAsync(user, loginDto.Password,false);


if (!result.Succeeded)
return Unauthorized("Email or Password not found/incorrect");

return Ok(
new NewUserDto
{

Email = user.Email,
Token = _tokenService.CreateToken(user)
});
}
[HttpPost("login")]
public async Task<IActionResult> Login(LoginDto loginDto)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);

var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Email == loginDto.Email);

if (user == null)
return Unauthorized("Invalid Email");


var result = await _signInManager.CheckPasswordSignInAsync(user, loginDto.Password,false);


if (!result.Succeeded)
return Unauthorized("Email or Password not found/incorrect");

return Ok(
new NewUserDto
{

Email = user.Email,
Token = _tokenService.CreateToken(user)
});
}
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
canton7
canton74w ago
I'm confused. Nothing in that code appears to have anything to do with base64 strings?
clownshark5503
I'm also confused for the same reason
canton7
canton74w ago
Your code doesn't even have any mention of CheckPasswordSignInAsync, but from your question that seems to be important?
clownshark5503
Ah its in the middle, the whole line is: _signInManager.CheckPasswordSignInAsync(user, loginDto.Password,false);
canton7
canton74w ago
And what does it do, and where does the base64 string come from?
clownshark5503
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));
canton7
canton74w ago
I still don't have any information which lets me help you What line throws the exception?
clownshark5503
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.UserManager1.VerifyPasswordAsync(IUserPasswordStore1 store, TUser user, String password) at Microsoft.AspNetCore.Identity.UserManager1.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
Want results from more Discord servers?
Add your server