feat : securité password avec bcrypt

Multiplayer_Php
Maxence GUITARD 1 year ago
parent 1aa6120226
commit 1674e13065

@ -18,6 +18,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" /> <PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Blazorise.Bootstrap" Version="1.4.0" /> <PackageReference Include="Blazorise.Bootstrap" Version="1.4.0" />

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Cryptography.KeyDerivation; using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using BCrypt.Net;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
@ -22,18 +23,24 @@ public class AdministratorModel
public void HashPassword(string password) public void HashPassword(string password)
{ {
using (MD5 md5 = MD5.Create()) this.HashedPassword = BCrypt.Net.BCrypt.HashPassword(password, BCrypt.Net.BCrypt.GenerateSalt());
{
byte[] inputBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
HashedPassword = sb.ToString();
}
} }
//public void HashPassword(string password)
//{
// using (MD5 md5 = MD5.Create())
// {
// byte[] inputBytes = Encoding.UTF8.GetBytes(password);
// byte[] hashBytes = md5.ComputeHash(inputBytes);
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < hashBytes.Length; i++)
// {
// sb.Append(hashBytes[i].ToString("x2"));
// }
// HashedPassword = sb.ToString();
// }
//}
} }

@ -21,18 +21,23 @@ public class PlayerModel
public void HashPassword(string password) public void HashPassword(string password)
{ {
using (MD5 md5 = MD5.Create()) this.HashedPassword = BCrypt.Net.BCrypt.HashPassword(password, BCrypt.Net.BCrypt.GenerateSalt());
{
byte[] inputBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
HashedPassword = sb.ToString();
}
} }
//public void HashPassword(string password)
//{
// using (MD5 md5 = MD5.Create())
// {
// byte[] inputBytes = Encoding.UTF8.GetBytes(password);
// byte[] hashBytes = md5.ComputeHash(inputBytes);
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < hashBytes.Length; i++)
// {
// sb.Append(hashBytes[i].ToString("x2"));
// }
// HashedPassword = sb.ToString();
// }
//}
} }

@ -10,6 +10,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" /> <PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" /> <PackageReference Include="MSTest.TestFramework" Version="3.0.4" />

Loading…
Cancel
Save