passport.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package model
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. )
  6. const (
  7. _cloudSalt = "bi_clould_tencent_01"
  8. )
  9. // AsoAccount aso account.
  10. type AsoAccount struct {
  11. Mid int64 `json:"mid"`
  12. Userid string `json:"userid"`
  13. Uname string `json:"uname"`
  14. Pwd string `json:"pwd"`
  15. Salt string `json:"salt"`
  16. Email string `json:"email"`
  17. Tel string `json:"tel"`
  18. CountryID int64 `json:"country_id"`
  19. MobileVerified int8 `json:"mobile_verified"`
  20. Isleak int8 `json:"isleak"`
  21. Mtime string `json:"mtime"`
  22. }
  23. // OriginAsoAccount origin aso account.
  24. type OriginAsoAccount struct {
  25. Mid int64 `json:"mid"`
  26. Userid string `json:"userid"`
  27. Uname string `json:"uname"`
  28. Pwd string `json:"pwd"`
  29. Salt string `json:"salt"`
  30. Email string `json:"email"`
  31. Tel string `json:"tel"`
  32. CountryID int64 `json:"country_id"`
  33. MobileVerified int8 `json:"mobile_verified"`
  34. Isleak int8 `json:"isleak"`
  35. Mtime string `json:"modify_time"`
  36. }
  37. // Default doHash aso account, including the followings fields: userid, uname, pwd, email, tel.
  38. func Default(a *OriginAsoAccount) *AsoAccount {
  39. return &AsoAccount{
  40. Mid: a.Mid,
  41. Userid: a.Userid,
  42. Uname: a.Uname,
  43. Pwd: doHash(a.Pwd, _cloudSalt),
  44. Salt: a.Salt,
  45. Email: doHash(a.Email, _cloudSalt),
  46. Tel: doHash(a.Tel, _cloudSalt),
  47. CountryID: a.CountryID,
  48. MobileVerified: a.MobileVerified,
  49. Isleak: a.Isleak,
  50. Mtime: a.Mtime,
  51. }
  52. }
  53. // DefaultHash hash a plain text using default salt.
  54. func DefaultHash(plaintext string) string {
  55. return doHash(plaintext, _cloudSalt)
  56. }
  57. func doHash(plaintext, salt string) string {
  58. if plaintext == "" {
  59. return ""
  60. }
  61. hash := md5.New()
  62. hash.Write([]byte(plaintext))
  63. hash.Write([]byte(salt))
  64. md := hash.Sum(nil)
  65. return hex.EncodeToString(md)
  66. }