-
-
Save default-writer/fe3bc4c85f87e14783ca95fc7e9b37b5 to your computer and use it in GitHub Desktop.
Check standart django password in go language
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/sha256" | |
"encoding/base64" | |
"fmt" | |
"golang.org/x/crypto/pbkdf2" | |
"strconv" | |
"strings" | |
) | |
func CheckDjangoPassword(password string, encodedPassword string) bool { | |
passArr := strings.Split(encodedPassword, "$") | |
//method := passArr[0] | |
iter, _ := strconv.Atoi(passArr[1]) | |
salt := passArr[2] | |
shapass := passArr[3] | |
dk := pbkdf2.Key([]byte(password), []byte(salt), iter, 32, sha256.New) | |
pass := base64.StdEncoding.EncodeToString(dk) | |
return pass == shapass | |
} | |
func main() { | |
pass := "pbkdf2_sha256$120000$BS5dRBxJCbcV$H6gcZx2xXtHGaiquZGvV7o/gqhTtUWEy7xWBeyEEfKo=" | |
fmt.Println(CheckDjangoPassword("testpassword",pass)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment