func userSave(result []string) bool {
//result[0] = login
//result[1] = email
//result[2] = pass
var salt string = newSalt()
if salt == "err" {
return false
}
var pass string = passwordHash(salt + result[2] + salt + result[1] + salt + result[1] + salt + result[2] + salt + result[0])
res, err := DB.Exec("INSERT INTO users (login, email, pass,salt)VALUES(?,?,?,?)", string(xxtea.Encrypt([]byte(v.Trim(result[0])), X_secret)), string(xxtea.Encrypt([]byte(v.Trim(result[1])), X_secret)), pass, salt)
if err != nil {
print(err)
return false
}
insertId, err := res.LastInsertId()
if err != nil {
print(err)
return false
}
print(insertId)
return true
}
func newSalt() string {
rb := make([]byte, 64)
_, err := rand.Read(rb)
if err != nil {
return "err"
}
return base64.URLEncoding.EncodeToString(rb)
}
func passwordHash(pass string) string {
text := v.Trim(pass)
hash := sha512.New()
hash.Write([]byte(text))
return1 := hex.EncodeToString(hash.Sum(nil))
var i int = 0
hashi := sha256.New()
for i <= 10 {
i = i + 1
hashi.Write([]byte(return1))
return1 = hex.EncodeToString(hashi.Sum(nil))
}
return return1
}
//result[0] = login
//result[1] = email
//result[2] = pass
var pass string = passwordHash(salt + result[2] + salt + result[1] + salt + result[1] + salt + result[2] + salt + result[0])
func passwordHash(pass string) string {
text := v.Trim(pass)
hash := sha512.New()
hash.Write([]byte(text))
return1 := hex.EncodeToString(hash.Sum(nil))
var i int = 0
hashi := sha256.New()
for i <= 10 {
i = i + 1
hashi.Write([]byte(return1))
return1 = hex.EncodeToString(hashi.Sum(nil))
}
return return1
}