model.go 2.4 KB

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