This repository has been archived by the owner on Feb 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
account.go
70 lines (59 loc) · 1.83 KB
/
account.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"crypto/sha512"
"encoding/hex"
"fmt"
"github.com/Disconnect24/Mail-GO/utilities"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
"net/http"
)
func Account(c *gin.Context) {
var is string
// Check if we should use `=` for a Wii or
// `:` for the Homebrew patcher.
if c.Request.URL.Path == "/cgi-bin/account.cgi" {
is = "="
} else {
is = ":"
}
wiiID := c.Query("mlid")
if !utilities.FriendCodeIsValid(wiiID) {
TypedErrorResponse(c, 610, is, "Invalid Wii Friend Code.")
return
}
c.Header("Content-Type", "text/plain;charset=utf-8")
stmt, err := db.Prepare("INSERT IGNORE INTO `accounts` (`mlid`,`passwd`, `mlchkid` ) VALUES (?, ?, ?)")
if err != nil {
TypedErrorResponse(c, 410, is, "Database error.")
utilities.LogError(ravenClient, "Unable to prepare account statement", err)
return
}
passwd := utilities.RandStringBytesMaskImprSrc(16)
passwdByte := sha512.Sum512(append(salt, []byte(passwd)...))
passwdHash := hex.EncodeToString(passwdByte[:])
mlchkid := utilities.RandStringBytesMaskImprSrc(32)
mlchkidByte := sha512.Sum512(append(salt, []byte(mlchkid)...))
mlchkidHash := hex.EncodeToString(mlchkidByte[:])
result, err := stmt.Exec(wiiID, passwdHash, mlchkidHash)
if err != nil {
TypedErrorResponse(c, 410, is, "Database error.")
utilities.LogError(ravenClient, "Unable to execute statement", err)
return
}
affected, err := result.RowsAffected()
if err != nil {
TypedErrorResponse(c, 410, is, "Database error.")
utilities.LogError(ravenClient, "Unable to get rows affected", err)
return
}
if affected == 0 {
TypedErrorResponse(c, 211, is, "Duplicate registration.")
return
}
c.String(http.StatusOK, fmt.Sprint("cd", is, "100", "\n",
"msg", is, "Success.", "\n",
"mlid", is, wiiID, "\n",
"passwd", is, passwd, "\n",
"mlchkid", is, mlchkid, "\n"))
}