-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserpasswordcount.go
52 lines (45 loc) · 1.03 KB
/
userpasswordcount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
)
func main() {
// Parse command line flags
threshold := flag.Int("t", 0, "Threshold for username occurrences")
flag.Parse()
// Open the file
file, err := os.Open("password_trim.txt")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()
// Initialize a map to store username occurrences
occurrences := make(map[string]int)
// Read the file line by line
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Split(line, ":")
if len(parts) != 2 {
fmt.Println("Invalid line format:", line)
continue
}
username := parts[0]
occurrences[username]++
}
// Check for any errors encountered during scanning
if err := scanner.Err(); err != nil {
fmt.Println("Error scanning file:", err)
return
}
// Print usernames that occur more than the threshold
for username, count := range occurrences {
if count > *threshold {
fmt.Printf("%s occurs %d times\n", username, count)
}
}
}