Created
August 2, 2023 06:49
-
-
Save M0nteCarl0/a0d1f2f6b0fc8612b2ffc2c01ceee6df to your computer and use it in GitHub Desktop.
parser pwned_passwd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/sha1" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
"strings" | |
) | |
func main() { | |
// ввод пароля(тестовый) | |
password := os.Args[1] | |
fmt.Println(check(password)) | |
} | |
func check(passwd string) string { | |
i := fmt.Sprintf("%X", sha1.Sum([]byte(passwd))) | |
r := strings.ToUpper(i[:5]) | |
resp, err := http.Get("https://api.pwnedpasswords.com/range/" + r) | |
if err != nil { | |
return "Something went wrong! Try again" | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
return "Something went wrong! Try again" | |
} | |
lines := strings.Split(string(body), "\n") | |
e := i[5:40] | |
for _, line := range lines { | |
f := strings.Split(line, ":")[0] | |
t := strings.Split(line, ":")[1] | |
if t != "" && e == f { | |
res := "Oh no, pwned!" | |
if t == "1" { | |
time := "time" | |
return fmt.Sprintf("%s\nThis password has been seen %s %s before", res, t, time) | |
} | |
time := "times" | |
return fmt.Sprintf("%s\nThis password has been seen %s %s before", res, t, time) | |
} | |
} | |
return "Good news — no pwnage found!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment