@@ -16,6 +16,7 @@ pub fn help(){
16
16
println ! ( " -j,--json | Print results in json format" ) ;
17
17
println ! ( " -s,--single | Print OTP codes in single mode" ) ;
18
18
println ! ( " -in,--info [ID] | Print info of choosen OTP code" ) ;
19
+ println ! ( " -chpw,--change-password | Change the database password" ) ;
19
20
println ! ( " -h,--help | Print this help" ) ;
20
21
}
21
22
@@ -177,6 +178,28 @@ pub fn info(args: Vec<String>){
177
178
}
178
179
}
179
180
else {
180
- println ! ( "Invalid arguments, type cotp --info" ) ;
181
+ println ! ( "Invalid arguments, type cotp --info [ID] " ) ;
181
182
}
182
- }
183
+ }
184
+
185
+ pub fn change_password ( args : Vec < String > ) {
186
+ if args. len ( ) == 2 {
187
+ let old_password = & cryptograpy:: prompt_for_passwords ( "Old password: " , 8 , false ) ;
188
+ let decrypted_text = database_loader:: read_decrypted_text ( old_password) ;
189
+ match decrypted_text{
190
+ Ok ( s) => {
191
+ let new_password = & cryptograpy:: prompt_for_passwords ( "New password: " , 8 , true ) ;
192
+ match database_loader:: overwrite_database_json ( & s, new_password) {
193
+ Ok ( ( ) ) => println ! ( "Password changed" ) ,
194
+ Err ( e) => eprintln ! ( "An error has occurred: {}" , e) ,
195
+ }
196
+ } ,
197
+ Err ( e) => {
198
+ eprintln ! ( "An error has occurred: {}" , e) ;
199
+ }
200
+ }
201
+ }
202
+ else {
203
+ println ! ( "Invalid arguments, type cotp --change-password" ) ;
204
+ }
205
+ }
0 commit comments