Created
September 4, 2018 19:35
-
-
Save mcihad/0ebb49b8d68f9993ae331d8be51f83f6 to your computer and use it in GitHub Desktop.
Check standart django password in go language
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
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