Fix hashCode to password for stub and for the reste

pull/19/head
Matheo THIERRY 2 years ago
parent 4129d5399f
commit dbac7bb6b6

@ -14,6 +14,9 @@ namespace Biblioteque_de_Class
private string Email { get; set; }
[DataMember]
private string Password { get; set; }
[DataMember]
private string Picture { get; set; }
[DataMember]
private Theme Theme;
[DataMember]
private List<Note> NoteList;
@ -31,6 +34,7 @@ namespace Biblioteque_de_Class
Username = username;
Email = email;
Password = password;
Picture = "defaultpicture.png";
NoteList = new List<Note>();
TagList = new List<Tags>();
FavList = new List<Note>();
@ -40,6 +44,7 @@ namespace Biblioteque_de_Class
public string GetUsername() { return Username; }
public string GetEmail() { return Email; }
public string GetPassword() { return Password; }
public string GetPicture() { return Picture;}
public Theme GetTheme() { return Theme; }
public List<Note> GetNoteList() { return NoteList; }
public List<Tags> GetTagList() { return TagList; }
@ -51,6 +56,7 @@ namespace Biblioteque_de_Class
public void SetUsername(string username) { Username = username; }
public void SetEmail(string email) { Email = email; }
public void SetPassword(string password) { Password = password; }
public void SetPicture(string picture) { Picture = picture; }
public void SetTheme(Theme theme) { Theme = theme; }
public void SetIsConnected(bool isConnected) { IsConnected = isConnected; }

@ -7,10 +7,6 @@ using System.Text;
// load database
PersistenceManager manager = new(new Stub());
Database db = manager.LoadDatabaseData();
foreach(User user in db.GetUserList())
{
user.SetPassword(GetSHA256Hash(user.GetPassword()));
}
// initialization zone==============================================================================
@ -139,22 +135,6 @@ List<string>? choix_couleur()
return colorList;
}
static string GetSHA256Hash(string input)
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
while (menu)
{
Console.WriteLine("\n|--------------------------------------|");
@ -190,7 +170,6 @@ while (menu)
Console.WriteLine("\nEntrez un password :");
string? password = Console.ReadLine();
if (password == null) { continue; }
password = GetSHA256Hash(password);
try
{
u = db.GetUser(nom);
@ -202,7 +181,7 @@ while (menu)
}
if (!connection)
{
if (Database.ComparePassword(u, password))
if (Database.ComparePassword(u, password.GetHashCode().ToString()))
{
u.SetIsConnected(true);
Console.WriteLine("\nConnection réussie !\n");
@ -234,8 +213,7 @@ while (menu)
}
catch (AlreadyUsedException)
{
password = GetSHA256Hash(password);
u = new User(nom, "", password);
u = new User(nom, "", password.GetHashCode().ToString());
db.AddUser(u);
db.GetUser(nom).SetIsConnected(true);
Console.WriteLine("\nConnection réussie !\n");
@ -548,8 +526,7 @@ while (u.GetIsConnected())
Console.WriteLine("\nLe mot de passe doit contenir au moins 8 caractères.\n");
break;
}
wantedNewPassword = GetSHA256Hash(wantedNewPassword);
if(wantedNewPassword == u.GetPassword()){
if(wantedNewPassword.GetHashCode().ToString() == u.GetPassword()){
Console.WriteLine("\nLe nouveau mot de passe doit être différent de l'ancien.\n");
break;
}

@ -4,8 +4,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Security.Cryptography;
using System.Threading.Tasks;
static string GetSHA256Hash(string input)
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
namespace Notus_Persistance
{
public class Stub : IManager
@ -59,6 +76,10 @@ namespace Notus_Persistance
colorListHexaCode = new("000000,FFFFFF,000000".Split(','));
database.AddTheme(new Theme("Theme_3", colorListHexaCode));
foreach (User user in database.GetUserList())
{
user.SetPassword(GetSHA256Hash(user.GetPassword()));
}
return database;
}

Loading…
Cancel
Save