11using System . ComponentModel ;
2- using Upsilon . Apps . PassKey . Core . Internal . Utils ;
3- using Upsilon . Apps . PassKey . Core . Public . Enums ;
4- using Upsilon . Apps . PassKey . Core . Public . Interfaces ;
2+ using Upsilon . Apps . Passkey . Core . Utils ;
3+ using Upsilon . Apps . Passkey . Interfaces ;
4+ using Upsilon . Apps . Passkey . Interfaces . Enums ;
55
6- namespace Upsilon . Apps . PassKey . Core . Internal . Models
6+ namespace Upsilon . Apps . Passkey . Core . Models
77{
88 internal sealed class Account : IAccount
99 {
1010 #region IAccount interface explicit Internal
1111
1212 string IItem . ItemId => Database . Get ( ItemId ) ;
13+
14+ IDatabase IItem . Database => Database ;
15+
1316 IService IAccount . Service => Database . Get ( Service ) ;
1417
1518 string IAccount . Label
@@ -19,18 +22,20 @@ string IAccount.Label
1922 itemName : ToString ( ) ,
2023 fieldName : nameof ( Label ) ,
2124 needsReview : false ,
22- value : value ,
25+ oldValue : Label ,
26+ newValue : value ,
2327 readableValue : value ) ;
2428 }
2529
26- string [ ] IAccount . Identifiants
30+ string [ ] IAccount . Identifiers
2731 {
28- get => Database . Get ( Identifiants ) ;
29- set => Identifiants = Database . AutoSave . UpdateValue ( ItemId ,
32+ get => Database . Get ( Identifiers ) ;
33+ set => Identifiers = Database . AutoSave . UpdateValue ( ItemId ,
3034 itemName : ToString ( ) ,
31- fieldName : nameof ( Identifiants ) ,
35+ fieldName : nameof ( Identifiers ) ,
3236 needsReview : true ,
33- value : value ,
37+ oldValue : Identifiers ,
38+ newValue : value ,
3439 readableValue : $ "({ string . Join ( ", " , value ) } )") ;
3540 }
3641
@@ -39,17 +44,34 @@ string IAccount.Password
3944 get => Database . Get ( Password ) ;
4045 set
4146 {
42- if ( ! string . IsNullOrEmpty ( value ) )
47+ if ( ! string . IsNullOrEmpty ( value )
48+ && Password != value )
4349 {
50+ Dictionary < DateTime , string > oldPasswords = Passwords . CloneWith ( Database . SerializationCenter ) ;
4451 Passwords [ DateTime . Now ] = Password = value ;
4552
4653 if ( _service != null )
4754 {
55+ if ( Service . User . NumberOfOldPasswordToKeep != 0 )
56+ {
57+ DateTime [ ] datesToRemove = [ .. Passwords . Keys
58+ . OrderBy ( x => x )
59+ . Take ( Passwords . Count > Service . User . NumberOfOldPasswordToKeep
60+ ? Passwords . Count - Service . User . NumberOfOldPasswordToKeep
61+ : 0 ) ] ;
62+
63+ foreach ( DateTime dateToRemove in datesToRemove )
64+ {
65+ _ = Passwords . Remove ( dateToRemove ) ;
66+ }
67+ }
68+
4869 _ = Database . AutoSave . UpdateValue ( ItemId ,
4970 itemName : ToString ( ) ,
5071 fieldName : nameof ( Password ) ,
5172 needsReview : true ,
52- value : Passwords ,
73+ oldValue : oldPasswords ,
74+ newValue : Passwords ,
5375 readableValue : string . Empty ) ;
5476 }
5577 }
@@ -65,7 +87,8 @@ string IAccount.Notes
6587 itemName : ToString ( ) ,
6688 fieldName : nameof ( Notes ) ,
6789 needsReview : false ,
68- value : value ,
90+ oldValue : Notes ,
91+ newValue : value ,
6992 readableValue : value ) ;
7093 }
7194
@@ -76,7 +99,8 @@ int IAccount.PasswordUpdateReminderDelay
7699 itemName : ToString ( ) ,
77100 fieldName : nameof ( PasswordUpdateReminderDelay ) ,
78101 needsReview : false ,
79- value : value ,
102+ oldValue : PasswordUpdateReminderDelay ,
103+ newValue : value ,
80104 readableValue : value . ToString ( ) ) ;
81105 }
82106
@@ -87,7 +111,8 @@ AccountOption IAccount.Options
87111 itemName : ToString ( ) ,
88112 fieldName : nameof ( Options ) ,
89113 needsReview : false ,
90- value : value ,
114+ oldValue : Options ,
115+ newValue : value ,
91116 readableValue : value . ToString ( ) ) ;
92117 }
93118
@@ -105,7 +130,7 @@ internal Service Service
105130 }
106131
107132 public string Label { get ; set ; } = string . Empty ;
108- public string [ ] Identifiants { get ; set ; } = [ ] ;
133+ public string [ ] Identifiers { get ; set ; } = [ ] ;
109134 public string Password { get ; set ; } = string . Empty ;
110135 public Dictionary < DateTime , string > Passwords { get ; set ; } = [ ] ;
111136 public string Notes { get ; set ; } = string . Empty ;
@@ -136,23 +161,23 @@ public void Apply(Change change)
136161 switch ( change . FieldName )
137162 {
138163 case nameof ( Label ) :
139- Label = Database . SerializationCenter . Deserialize < string > ( change . Value ) ;
164+ Label = change . NewValue . DeserializeTo < string > ( Database . SerializationCenter ) ;
140165 break ;
141- case nameof ( Identifiants ) :
142- Identifiants = Database . SerializationCenter . Deserialize < string [ ] > ( change . Value ) ;
166+ case nameof ( Identifiers ) :
167+ Identifiers = change . NewValue . DeserializeTo < string [ ] > ( Database . SerializationCenter ) ;
143168 break ;
144169 case nameof ( Notes ) :
145- Notes = Database . SerializationCenter . Deserialize < string > ( change . Value ) ;
170+ Notes = change . NewValue . DeserializeTo < string > ( Database . SerializationCenter ) ;
146171 break ;
147172 case nameof ( Password ) :
148- Passwords = Database . SerializationCenter . Deserialize < Dictionary < DateTime , string > > ( change . Value ) ;
173+ Passwords = change . NewValue . DeserializeTo < Dictionary < DateTime , string > > ( Database . SerializationCenter ) ;
149174 Password = Passwords . Count != 0 ? Passwords [ Passwords . Keys . Max ( ) ] : string . Empty ;
150175 break ;
151176 case nameof ( PasswordUpdateReminderDelay ) :
152- PasswordUpdateReminderDelay = Database . SerializationCenter . Deserialize < int > ( change . Value ) ;
177+ PasswordUpdateReminderDelay = change . NewValue . DeserializeTo < int > ( Database . SerializationCenter ) ;
153178 break ;
154179 case nameof ( Options ) :
155- Options = Database . SerializationCenter . Deserialize < AccountOption > ( change . Value ) ;
180+ Options = change . NewValue . DeserializeTo < AccountOption > ( Database . SerializationCenter ) ;
156181 break ;
157182 default :
158183 throw new InvalidDataException ( "FieldName not valid" ) ;
@@ -172,7 +197,7 @@ public override string ToString()
172197 account += $ "{ Label } ";
173198 }
174199
175- return account + $ "({ string . Join ( ", " , Identifiants ) } )";
200+ return account + $ "({ string . Join ( ", " , Identifiers ) } )";
176201 }
177202 }
178203}
0 commit comments