~~~
func (c *LoginController) Post() {
username := c.GetString("username")
password := c.GetString("password")
w := md5.New()
io.WriteString(w, password) //將str寫入到w中
bw := w.Sum(nil) //w.Sum(nil)將w的hash轉成[]byte格式
// md5str2 := fmt.Sprintf("%x", bw) //將 bw 轉成字符串
md5str := hex.EncodeToString(bw) //將 bw 轉成字符串
o := orm.NewOrm()
qs := o.QueryTable(new(models.User))
res := qs.Filter("username", username).Filter("pwd", md5str).Exist()
if res {
c.SetSession("user_name", username)
c.Redirect(beego.URLFor("MainsController.Get"), 302)
} else {
c.Redirect(beego.URLFor("LoginController.Get"), 302)
}
}
~~~