-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheckHash.go
More file actions
39 lines (31 loc) · 813 Bytes
/
checkHash.go
File metadata and controls
39 lines (31 loc) · 813 Bytes
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
package main
import (
"bytes"
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"strings"
)
func checkMD5RAW(hash Hash, password string) bool {
md := md5.Sum([]byte(password))
if bytes.Equal(hash.Hash, md[:]) {
return true
}
return false
}
func checkMD5SaltPreSHA1SaltPre(hash Hash, password string) bool {
// md5(salt1.sha1(salt2.password)) with upper hex output for hashes
var innerBuffer bytes.Buffer
var externalBuffer bytes.Buffer
innerBuffer.Write(hash.Salts[1])
innerBuffer.WriteString(password)
innerSum := sha1.Sum(innerBuffer.Bytes())
hexInnerSum := strings.ToUpper(hex.EncodeToString(innerSum[:]))
externalBuffer.Write(hash.Salts[0])
externalBuffer.WriteString(hexInnerSum)
md := md5.Sum(externalBuffer.Bytes())
if bytes.Equal(hash.Hash, md[:]) {
return true
}
return false
}