Last active
October 9, 2022 21:15
-
-
Save fsmv/02c636d4da58106f113049ee45a62f50 to your computer and use it in GitHub Desktop.
A runnable go script that creates an http basic auth password hash compatible with .htaccess (this is just the password part, you have to add username:<hash>)
This file contains hidden or 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
/*?sr/bin/env go run "$0" "$@"; exit $? #*/ | |
// This is actually not a shebang, the first line is both valid shell script and valid go code | |
// Just run: chmod +x pass.go; ./pass.go | |
package main | |
import ( | |
"bufio" | |
"crypto/sha256" | |
"encoding/base64" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
) | |
func main() { | |
fmt.Printf("Type your password (not hidden) then press enter: ") | |
rawPw, err := bufio.NewReader(os.Stdin).ReadString('\n') | |
if err != nil { | |
log.Fatal(err) | |
} | |
password := strings.TrimSpace(rawPw) | |
hash := sha256.Sum256([]byte(password)) | |
fmt.Printf("{SHA}%v", base64.StdEncoding.EncodeToString(hash[:])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment