@@ -42,26 +42,32 @@ func getHomePasswordFilePath() (string, error) {
4242}
4343
4444func CrackPassword (archivePath string ) string {
45- passwordFilePath , err := getHomePasswordFilePath ()
46- if err != nil {
47- fmt .Printf ("Error: %v\n " , err )
48- return ""
49- }
45+ return CrackPasswordWithList (archivePath , nil )
46+ }
5047
51- passwords , err := os .ReadFile (passwordFilePath )
52- if err != nil {
53- fmt .Printf ("Error: failed to read password file: %v\n " , err )
54- return ""
55- }
48+ func CrackPasswordWithList (archivePath string , passwords []string ) string {
49+ if passwords == nil {
50+ passwordFilePath , err := getHomePasswordFilePath ()
51+ if err != nil {
52+ fmt .Printf ("Error: %v\n " , err )
53+ return ""
54+ }
5655
57- passwordList := parsePasswords (string (passwords ))
58- if len (passwordList ) == 0 {
59- fmt .Println ("Error: no valid passwords found in dictionary" )
60- fmt .Printf ("Please add passwords to: %s\n " , passwordFilePath )
61- return ""
56+ passwordData , err := os .ReadFile (passwordFilePath )
57+ if err != nil {
58+ fmt .Printf ("Error: failed to read password file: %v\n " , err )
59+ return ""
60+ }
61+
62+ passwords = parsePasswords (string (passwordData ))
63+ if len (passwords ) == 0 {
64+ fmt .Println ("Error: no valid passwords found in dictionary" )
65+ fmt .Printf ("Please add passwords to: %s\n " , passwordFilePath )
66+ return ""
67+ }
6268 }
6369
64- result := crackWithWorkers (archivePath , passwordList , defaultMaxWorkers )
70+ result := crackWithWorkers (archivePath , passwords , defaultMaxWorkers )
6571 if result != "" {
6672 fmt .Printf ("Password found: %s\n " , result )
6773 } else {
0 commit comments