@@ -16,6 +16,7 @@ pub fn help(){
1616 println ! ( " -j,--json | Print results in json format" ) ;
1717 println ! ( " -s,--single | Print OTP codes in single mode" ) ;
1818 println ! ( " -in,--info [ID] | Print info of choosen OTP code" ) ;
19+ println ! ( " -chpw,--change-password | Change the database password" ) ;
1920 println ! ( " -h,--help | Print this help" ) ;
2021}
2122
@@ -177,6 +178,28 @@ pub fn info(args: Vec<String>){
177178 }
178179 }
179180 else {
180- println ! ( "Invalid arguments, type cotp --info" ) ;
181+ println ! ( "Invalid arguments, type cotp --info [ID] " ) ;
181182 }
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