From 99689cab87cce02f71c660faa4a0ddd1bbd02570 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Thu, 11 May 2023 12:00:44 +0200 Subject: [PATCH 1/9] IPasswordManager, PasswordManager and User are well advanced, but methods Equals() and Tostring() are missing. --- MCTG/ConsoleApp/Program.cs | 44 +++++++++--------- MCTG/ConsoleApp/Stub.cs | 21 ++++++--- MCTG/Model/User/IPasswordManager.cs | 5 +-- MCTG/Model/User/PasswordManager.cs | 17 +++---- MCTG/Model/User/User.cs | 47 +++++++++++++------- MCTG/Tests/Model_UnitTests/test_unit_user.cs | 2 +- 6 files changed, 82 insertions(+), 54 deletions(-) diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 773f61b..e082f54 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -1,21 +1,25 @@ -// See https://aka.ms/new-console-template for more information - +// See https://aka.ms/new-console-template for more information + using ConsoleApp; -using Model; - - -Console.WriteLine("Hello, World!\n\n"); - - -// TESTS: - -Stub stub = new Stub(); - -List recipes = stub.LoadRecipes(); -List recipeCollections = stub.LoadRecipeCollection(); - -foreach (Recipe r in recipes) - Console.WriteLine(r); - -foreach (RecipeCollection r in recipeCollections) - Console.WriteLine(r); +using Model; + + +Console.WriteLine("Hello, World!\n\n"); + + +// TESTS: + +Stub stub = new Stub(); + +List recipes = stub.LoadRecipes(); +List recipeCollections = stub.LoadRecipeCollection(); + +foreach (Recipe r in recipes) + Console.WriteLine(r); + +foreach (RecipeCollection r in recipeCollections) + Console.WriteLine(r); + +List users = stub.ConstrucList(); +foreach (User u in users) + Console.WriteLine(u); diff --git a/MCTG/ConsoleApp/Stub.cs b/MCTG/ConsoleApp/Stub.cs index bb8fa01..d21ac8a 100644 --- a/MCTG/ConsoleApp/Stub.cs +++ b/MCTG/ConsoleApp/Stub.cs @@ -7,8 +7,11 @@ using System.Threading.Tasks; namespace ConsoleApp { - internal struct Stub - { + + internal struct Stub + { + private IPasswordManager passwordManager = new PasswordManager(); + public List LoadRecipes() { List stub = new List(); @@ -41,20 +44,24 @@ namespace ConsoleApp }); return stub; } - + public List ConstrucList() { List Users = new List(); - User Roger = new User("Roger", "Rabbit", "carotte@mail.fr"); - User Dylan = new User("d", "r", "dr@mail.fr"); - User Val = new User("V", "entin", "Valentin@mail.fr"); + User Roger = new User("Roger", "Rabbit", "carotte@mail.fr",passwordManager.HashPassword("password")); + User Dylan = new User("d", "r", "dr@mail.fr", passwordManager.HashPassword("dede")); + User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); Users.Add(Roger); Users.Add(Dylan); Users.Add(Val); - + Val.Password = passwordManager.HashPassword("jeChange"); return Users; } + public Stub() + { + + } } } diff --git a/MCTG/Model/User/IPasswordManager.cs b/MCTG/Model/User/IPasswordManager.cs index 12f0e0a..a87d960 100644 --- a/MCTG/Model/User/IPasswordManager.cs +++ b/MCTG/Model/User/IPasswordManager.cs @@ -8,9 +8,8 @@ namespace Model { public interface IPasswordManager { - public void changePassword(User user, string newPassword); - public string HashPassword(User user); - public bool VerifyPassword(string hashedPassword); + public int HashPassword(string password); + public bool VerifyPassword(int hashedPassword,string password); } } diff --git a/MCTG/Model/User/PasswordManager.cs b/MCTG/Model/User/PasswordManager.cs index 59bc784..d762e42 100644 --- a/MCTG/Model/User/PasswordManager.cs +++ b/MCTG/Model/User/PasswordManager.cs @@ -8,19 +8,20 @@ namespace Model { public class PasswordManager : IPasswordManager { - public void changePassword(User user, string newPassword) - { - throw new NotImplementedException(); - } - public string HashPassword(User user) + public int HashPassword(string password) { - throw new NotImplementedException(); + int hashedPassword = password.GetHashCode(); + return hashedPassword; } - public bool VerifyPassword(string hashedPassword) + public bool VerifyPassword(int hashedPassword, string passwordEntered ) { - throw new NotImplementedException(); + int passwordEnteredHashed = passwordEntered.GetHashCode(); + if ( passwordEnteredHashed == hashedPassword) + return true; + else return false; + } } } diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index 3c6bf73..7805204 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -5,7 +5,8 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; - +using System.Text; + namespace Model { /// @@ -20,7 +21,7 @@ namespace Model private string surname=""; private string mail = ""; private string picture = ""; - private string password = ""; + private int password ; //private string defaultUserSavePath = ""; private List priorities; #endregion @@ -79,16 +80,16 @@ namespace Model } } - /// - /// Property to initiate password, change it, and - /// - public string Password - { - get { return password; } - - set { password = value; } + public int Password + { + get { return password; } + set + { + password = value; + } } - + + /// /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" /// when the value is null. @@ -111,12 +112,27 @@ namespace Model set=> priorities = value; } - public bool Equals(User other) + public bool Equals(User? other) { + if (other == null) return false; + if (other == this) return true; return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); } - - + /// + /// TODO gestion affichage d'un User + /// Il semblerait que j'ai un soucis avec la gestion du Enum + /// + /// + public override string ToString() + { + StringBuilder stringB = new StringBuilder($"{Name}{Surname}"); + foreach (Priority in Priorities) + { + stringB.AppendFormat("") + } + return stringB.ToString; + } + */ #endregion @@ -128,11 +144,12 @@ namespace Model /// The name of the user /// The surname of the user /// The user needs an email to login. - public User(string name, string surname, string mail) + public User(string name, string surname, string mail, int password) { Name = name; Surname = surname; Mail = mail; + Password = password; priorities = new List { Priority.Gourmet, Priority.Economic, diff --git a/MCTG/Tests/Model_UnitTests/test_unit_user.cs b/MCTG/Tests/Model_UnitTests/test_unit_user.cs index 943afa0..d57a7e8 100644 --- a/MCTG/Tests/Model_UnitTests/test_unit_user.cs +++ b/MCTG/Tests/Model_UnitTests/test_unit_user.cs @@ -12,7 +12,7 @@ namespace Model_UnitTests [Fact] public void TestConstructUser() { - User user = new User("Bob","Dylan", "bd@gmail.com"); + //User user = new User("Bob","Dylan", "bd@gmail.com"); //Assert. } } From b4ca357d926fdf8b4c16e6e1031892faa338cf0b Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Tue, 16 May 2023 16:48:34 +0200 Subject: [PATCH 2/9] I remove to_string() and I think user model is ready to use!! --- MCTG/ConsoleApp/Program.cs | 4 + MCTG/ConsoleApp/Stub.cs | 14 +- MCTG/Model/User/User.cs | 297 ++++++++++++++++++------------------- 3 files changed, 159 insertions(+), 156 deletions(-) diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index e082f54..fc1ca37 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -10,6 +10,7 @@ Console.WriteLine("Hello, World!\n\n"); // TESTS: Stub stub = new Stub(); +PasswordManager passwordManager = new PasswordManager(); List recipes = stub.LoadRecipes(); List recipeCollections = stub.LoadRecipeCollection(); @@ -23,3 +24,6 @@ foreach (RecipeCollection r in recipeCollections) List users = stub.ConstrucList(); foreach (User u in users) Console.WriteLine(u); + +bool isPassCorrect = stub.VerifPass(); +Console.WriteLine(isPassCorrect); diff --git a/MCTG/ConsoleApp/Stub.cs b/MCTG/ConsoleApp/Stub.cs index d21ac8a..7bbf872 100644 --- a/MCTG/ConsoleApp/Stub.cs +++ b/MCTG/ConsoleApp/Stub.cs @@ -56,9 +56,21 @@ namespace ConsoleApp Users.Add(Roger); Users.Add(Dylan); Users.Add(Val); - Val.Password = passwordManager.HashPassword("jeChange"); return Users; } + + public bool VerifPass() + { + User John = new User("John", "Doe", "JD@gmail.com", passwordManager.HashPassword("GIJD")); + string entryPass = "GIJD"; + + User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); + Val.Password = passwordManager.HashPassword("jeChange"); + + bool isPasswordCorrect = passwordManager.VerifyPassword(John.Password, entryPass); + + return isPasswordCorrect; + } public Stub() { diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index 7805204..a9d9ea4 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -1,85 +1,85 @@ -using System; -using System.Collections.Generic; -using System.Collections; -using System.Collections.ObjectModel; -using System.Threading.Tasks; -using System.Runtime.CompilerServices; -using System.Text.RegularExpressions; +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; using System.Text; -namespace Model -{ - /// - /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. - /// This user can login with a Id and password - /// - public class User : IEquatable - { - #region Private Attributes - - private string name=""; - private string surname=""; - private string mail = ""; - private string picture = ""; - private int password ; - //private string defaultUserSavePath = ""; - private List priorities; - #endregion - - #region Properties - - /// - /// Property to get Name of users and a setter - /// - /// Setter have Exception which is trigger when Name is null - public string Name - { - get { return name; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); - } - name = value; - } - } - - /// - /// Property to get Surname of users and a setter - /// - /// Setter have Exception which is trigger when Surname is null - public string Surname - { - get { return surname; } - private set - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); - } - surname = value; - } - } - - /// - /// Property to get mail of users and a setter - /// - /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his - /// account creation. - public string Mail - { - get { return mail; } - private init - { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Email vide!"); - } - mail = value; - } - } - +namespace Model +{ + /// + /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. + /// This user can login with a Id and password + /// + public class User : IEquatable + { + #region Private Attributes + + private string name=""; + private string surname=""; + private string mail = ""; + private string picture = ""; + private int password ; + //private string defaultUserSavePath = ""; + private List priorities; + #endregion + + #region Properties + + /// + /// Property to get Name of users and a setter + /// + /// Setter have Exception which is trigger when Name is null + public string Name + { + get { return name; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); + } + name = value; + } + } + + /// + /// Property to get Surname of users and a setter + /// + /// Setter have Exception which is trigger when Surname is null + public string Surname + { + get { return surname; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); + } + surname = value; + } + } + + /// + /// Property to get mail of users and a setter + /// + /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his + /// account creation. + public string Mail + { + get { return mail; } + private init + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Email vide!"); + } + mail = value; + } + } + public int Password { get { return password; } @@ -87,81 +87,68 @@ namespace Model { password = value; } - } - - - /// - /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" - /// when the value is null. - /// - public string ProfilPict - { - get => picture; - set => picture = value; - - } - - /// - /// This is the list of priorities specific tu the user. This list is initiate - /// by default. User could change it at will. - /// - - public List Priorities - { - get => priorities; - set=> priorities = value; - } - - public bool Equals(User? other) - { - if (other == null) return false; - if (other == this) return true; - return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); - } + } + + /// - /// TODO gestion affichage d'un User - /// Il semblerait que j'ai un soucis avec la gestion du Enum + /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" + /// when the value is null. /// - /// - public override string ToString() + public string ProfilPict { - StringBuilder stringB = new StringBuilder($"{Name}{Surname}"); - foreach (Priority in Priorities) - { - stringB.AppendFormat("") - } - return stringB.ToString; - } - */ - #endregion - - - #region Constructors - - /// - /// Construtors of user. - /// - /// The name of the user - /// The surname of the user - /// The user needs an email to login. - public User(string name, string surname, string mail, int password) - { - Name = name; - Surname = surname; - Mail = mail; - Password = password; - priorities = new List { - Priority.Gourmet, - Priority.Economic, - Priority.Fast, - Priority.Light, - Priority.Easy}; - ProfilPict = picture; - - } - - #endregion - - - } -} + get => picture; + set => picture = value; + + } + + /// + /// This is the list of priorities specific tu the user. This list is initiate + /// by default. User could change it at will. + /// + + public List Priorities + { + get => priorities; + set=> priorities = value; + } + + public bool Equals(User? other) + { + if (other == null) return false; + if (other == this) return true; + return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); + } + + + #endregion + + + #region Constructors + + /// + /// Construtors of user. + /// + /// The name of the user + /// The surname of the user + /// The user needs an email to login. + public User(string name, string surname, string mail, int password) + { + Name = name; + Surname = surname; + Mail = mail; + Password = password; + priorities = new List { + Priority.Gourmet, + Priority.Economic, + Priority.Fast, + Priority.Light, + Priority.Easy}; + ProfilPict = picture; + + } + + #endregion + + + } +} From 0f7459a71f1fcf5fc13d097702de293d2061010d Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Tue, 16 May 2023 16:59:35 +0200 Subject: [PATCH 3/9] conflict's resolution caused by switching branch too fast without saving --- MCTG/Model/Ingredient.cs | 13 +++++++++++++ MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 MCTG/Model/Ingredient.cs diff --git a/MCTG/Model/Ingredient.cs b/MCTG/Model/Ingredient.cs new file mode 100644 index 0000000..986444c --- /dev/null +++ b/MCTG/Model/Ingredient.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + internal class Ingredient + { + + } +} diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj index dc31a95..99f0f2e 100644 --- a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj @@ -1,4 +1,4 @@ - + net7.0 From 40e302a481caae467a8365af79cddc5b087e2a4e Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Tue, 16 May 2023 17:22:11 +0200 Subject: [PATCH 4/9] bis --- MCTG/Model/Ingredient/Ingredient.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 MCTG/Model/Ingredient/Ingredient.cs diff --git a/MCTG/Model/Ingredient/Ingredient.cs b/MCTG/Model/Ingredient/Ingredient.cs new file mode 100644 index 0000000..a30d0d0 --- /dev/null +++ b/MCTG/Model/Ingredient/Ingredient.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Ingredient +{ + internal class Ingredient + { + } +} From db4b1da0480698da00c2afc080e3706014299e59 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Wed, 17 May 2023 10:33:39 +0200 Subject: [PATCH 5/9] cleaning branch --- MCTG/Model/Ingredient.cs | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 MCTG/Model/Ingredient.cs diff --git a/MCTG/Model/Ingredient.cs b/MCTG/Model/Ingredient.cs deleted file mode 100644 index 986444c..0000000 --- a/MCTG/Model/Ingredient.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - internal class Ingredient - { - - } -} From ff6823c7d533fbbc8e2e3390bae66335c8224fb9 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Wed, 17 May 2023 10:37:07 +0200 Subject: [PATCH 6/9] Password property changed --- MCTG/Model/User/User.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index a9d9ea4..4af028d 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -82,11 +82,9 @@ namespace Model public int Password { - get { return password; } - set - { - password = value; - } + get => password; + set => password = value; + } From dcb515b79d428fdb626f9b4d03748a63894577ff Mon Sep 17 00:00:00 2001 From: Roxane Date: Fri, 19 May 2023 13:26:36 +0200 Subject: [PATCH 7/9] unit-tests for user class --- MCTG/Tests/Model_UnitTests/test_unit_user.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MCTG/Tests/Model_UnitTests/test_unit_user.cs b/MCTG/Tests/Model_UnitTests/test_unit_user.cs index d57a7e8..5df6579 100644 --- a/MCTG/Tests/Model_UnitTests/test_unit_user.cs +++ b/MCTG/Tests/Model_UnitTests/test_unit_user.cs @@ -12,8 +12,13 @@ namespace Model_UnitTests [Fact] public void TestConstructUser() { - //User user = new User("Bob","Dylan", "bd@gmail.com"); - //Assert. + PasswordManager passwordManager = new PasswordManager(); + User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby")); + Assert.Equal("Bob", user.Name); + Assert.Equal("Dylan", user.Surname); + Assert.Equal("bd@gmail.com", user.Mail); + Assert.Equal(passwordManager.HashPassword("bobby"), user.Password); + Assert.NotNull(user.Priorities); } } } From d4dcbc95eff0ac062c7c3a22b5a0f43cbc72669e Mon Sep 17 00:00:00 2001 From: Roxane Date: Fri, 19 May 2023 20:09:25 +0200 Subject: [PATCH 8/9] Follow Drone's advices and correct Equal property --- MCTG/Model/User/User.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index 4af028d..e3fff40 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -22,7 +22,6 @@ namespace Model private string mail = ""; private string picture = ""; private int password ; - //private string defaultUserSavePath = ""; private List priorities; #endregion From 5657230234603dc8ded3c59f89be2575d1c944f6 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Mon, 22 May 2023 11:26:20 +0200 Subject: [PATCH 9/9] correction of the Equals method --- MCTG/Model/User/User.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index e3fff40..b29949f 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -109,10 +109,16 @@ namespace Model set=> priorities = value; } - public bool Equals(User? other) + public override bool Equals(object? other) { if (other == null) return false; if (other == this) return true; + return Equals(other); + } + + public bool Equals(User? other) + { + if (other == null) return false; return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); }