konstantine
konstantine
CC#
Created by konstantine on 1/19/2024 in #help
BCrypt : EnhancedVerify() doesn't work
I also had to change the hashing method too
EnhancedHashPassword()
EnhancedHashPassword()
->
HashPassword()
HashPassword()
. It works, thank you ๐Ÿ™‚
3 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
I'm considering working with BCrypt instead of Identity
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
Thank you !! I don't get how to use Identity reading the code source of it, I'm a begginer, and C# is hard without the proper documentation ๐Ÿ˜ข I don't want to use it manually. I'm trying to use the whole framework, but I'm having a hard time! Here what I'm trying to do. I would like to hash the passwords of my users, when users create an account. And then to use it for the authentication part of the application.
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
Here my implementation on the Program.cs :
builder.Services.AddDefaultIdentity<User>().AddUserStore<DbNetflimContext>();
builder.Services.AddDefaultIdentity<User>().AddUserStore<DbNetflimContext>();
I installed 2 more NuGets : Microsoft.AspNetCore.Identity.EntityFrameworkCore and Microsoft.AspNetCore.Identity.UI
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
Hi @TeBeCo , I still have trouble using Identity, if you want to take a look... Here my post request :
[Route("api/[controller]")]
[ApiController]
public class UsersController(DbNetflimContext context, PasswordHasher<User> passwordHasher) : ControllerBase
{
private readonly DbNetflimContext _context = context;
private readonly PasswordHasher<User> _passwordHasher;
[...]

[HttpPost]
public async Task<ActionResult<User>> PostUser(User user)
{

Console.WriteLine($"Mot de passe avant hachage : {user.PasswordUser}");

user.PasswordUser = _passwordHasher.HashPassword(user, user.PasswordUser);

Console.WriteLine($"Mot de passe aprรจs hachage : {user.PasswordUser}");

_context.Users.Add(user);
string jsonString = JsonSerializer.Serialize(user);
_context.Users.Add(user);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (UserExists(user.UserId))
{
return Conflict();
}
else
{
throw;
}
}

return CreatedAtAction("GetUser", new { id = user.UserId }, user);
}
[Route("api/[controller]")]
[ApiController]
public class UsersController(DbNetflimContext context, PasswordHasher<User> passwordHasher) : ControllerBase
{
private readonly DbNetflimContext _context = context;
private readonly PasswordHasher<User> _passwordHasher;
[...]

[HttpPost]
public async Task<ActionResult<User>> PostUser(User user)
{

Console.WriteLine($"Mot de passe avant hachage : {user.PasswordUser}");

user.PasswordUser = _passwordHasher.HashPassword(user, user.PasswordUser);

Console.WriteLine($"Mot de passe aprรจs hachage : {user.PasswordUser}");

_context.Users.Add(user);
string jsonString = JsonSerializer.Serialize(user);
_context.Users.Add(user);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (UserExists(user.UserId))
{
return Conflict();
}
else
{
throw;
}
}

return CreatedAtAction("GetUser", new { id = user.UserId }, user);
}
I have 500 error from the frontend, I never enter the post request. And I have this issue:
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.PasswordHasher`1[ToDoAPI.Models.User]' while attempting to activate 'ToDoAPI.Controllers.UsersController'.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.PasswordHasher`1[ToDoAPI.Models.User]' while attempting to activate 'ToDoAPI.Controllers.UsersController'.
I can't implement correctly the dependance in the Program.cs
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
I tried to use this code https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Extensions.Core/src/PasswordHasher.cs And I have errors : -"no definition in Resources for InvalidPasswordHasherIterationCount", -"no definition in Resources for InvalidPasswordHasherCompatibilityMode"...
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
Thank you ๐Ÿ™‚ I often can't find what I want with Microsoft's documentation... Like, here, I have some infos about Identity methods but no examples for how I have to use them. Do I have to use
public virtual string HashPassword (TUser user, string password);
public virtual string HashPassword (TUser user, string password);
directly in my model ? Or in the controller ? I'm lost ^^
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
I work with the 8.0 version, is taht ok ? Thank you ๐Ÿ™‚
51 replies
CC#
Created by konstantine on 1/16/2024 in #help
โœ… Hashing password - ASP.NET Core Identity PasswordHasher
Thank's, but I don't find any clear and complete ressource on Identity and hashing password, i'ts directly Microsoft that gives the link of Andrew Lock's doc. Do you know any ?
51 replies