Advertisement
Guest User

Untitled

a guest
Jul 17th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using Conquer_Online_Server.DB.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Conquer_Online_Server.DB
  9. {
  10. public class AccountsTable
  11. {
  12. public enum AccountState : byte
  13. {
  14. NotActivated = 100,
  15. ProjectManager = 4,
  16. Entity = 2,
  17. Banned = 1,
  18. DoesntExist = 0
  19. }
  20. public string Username;
  21. public string Password;
  22. public string IP;
  23. public uint EntityID;
  24. public AccountState State;
  25. private int RandomKey;
  26. public bool Login(string username)
  27. {
  28. bool Exists = false;
  29. using(var context = new MyContext())
  30. {
  31. var acc = context.accounts.Find(username);
  32. if (acc == null)
  33. Exists = false;
  34. else
  35. {
  36. Exists = true;
  37. this.Username = acc.Username;
  38. this.Password = acc.Password;
  39. this.State = (AccountState)acc.State;
  40. this.IP = acc.IP;
  41. this.EntityID = (uint)acc.EntityID;
  42. }
  43. }
  44. return Exists;
  45. }
  46. public uint GenerateKey(int randomKey = 0)
  47. {
  48. if (randomKey == 0)
  49. RandomKey = Kernel.Random.Next(11, 253) % 100 + 1;
  50. return (uint)
  51. (Username.GetHashCode() *
  52. Password.GetHashCode() *
  53. RandomKey);
  54. }
  55. public void Save()
  56. {
  57. using (var db = new MyContext())
  58. {
  59. var acc = db.accounts.Find(this.Username);
  60. acc.EntityID = EntityID;
  61. acc.State = (byte)State;
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement