go实现wordpress密码加密
这两天帮一个朋友写的wordpress密码加密代码,这里保存一份
package main
import (
"crypto/md5"
"fmt"
)
func main() {
//wordpress数据库密码$P$B12345678.8beAbNGrptg9h4PwkOt9. 明文密码为 admin123
//我们把密码拆分为"$P$B与12345678与后22位
var top string = "$P$B" //密码前四位,php中固定格式
var salt string = "12345678" //salt为php中未随机生成8位字符串
var passwd string = "admin123" //明文密码
var itoa64 string = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
a := salt + passwd
has := md5.New()
has.Write([]byte(a))
b := string(has.Sum(nil))
for i := 1; i <= 8192; i++ {
a = b + passwd
has = md5.New()
has.Write([]byte(a))
b = string(has.Sum(nil))
}
var input string = b
var count int = 16
var output string
for i := 0; i < count; i++ {
var value int
value = int(input[i])
output = output + itoa64[(value&0x3f):(value&0x3f)+1]
i++
if i < count {
value = int(value) + (int(input[i]) << 8)
}
output = output + itoa64[((value>>6)&0x3f):((value>>6)&0x3f)+1]
if i > count {
break
}
i++
if i < count {
value = int(value) + (int(input[i]) << 16)
}
output = output + itoa64[((value>>12)&0x3f):((value>>12)&0x3f)+1]
if i > count {
break
}
output = output + itoa64[((value>>18)&0x3f):((value>>18)&0x3f)+1]
}
output = top + salt + output[0:22]
fmt.Println(output)
//打印输出 $P$B12345678.8beAbNGrptg9h4PwkOt9.
}
go语言最近才开始学习的,代码写得很low
完美封装可以看我朋友封装的
代码地址