Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. using GTANetworkServer;
  2. using Insight.Database;
  3. using Insight.Database.Providers.MySql;
  4. using MySql.Data.MySqlClient;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11. using BCr = BCrypt.Net;
  12.  
  13. namespace NewServer
  14. {
  15. public class Main : Script
  16. {
  17.  
  18. private static MySqlConnectionStringBuilder _database;
  19. private static IUserRepository _userRepository;
  20.  
  21. public Main()
  22. {
  23. API.onResourceStart += API_onResourceStart;
  24. }
  25.  
  26. private void API_onResourceStart()
  27. {
  28. MySqlInsightDbProvider.RegisterProvider();
  29.  
  30. _database = new MySqlConnectionStringBuilder("server=94.23.90.14;user=db_23788;database=db_23788;port=3306;password=c8KycLLNCne1;");
  31.  
  32. _userRepository = _database.Connection().As<IUserRepository>();
  33. }
  34.  
  35.  
  36. [Command("ul", GreedyArg = true)]
  37. public void CMD_UserLogin(Client player, string password)
  38. {
  39. UserAccount account = _userRepository.GetAccount(player.name);
  40.  
  41. bool isPasswordCorrect = BCr.BCrypt.Verify(password, account.Hash);
  42.  
  43. if (isPasswordCorrect)
  44. {
  45. API.sendChatMessageToPlayer(player, "You're now logged in!");
  46. }
  47. else
  48. {
  49. API.sendChatMessageToPlayer(player, "Wrong password!");
  50. }
  51. }
  52.  
  53.  
  54. [Command("ur", GreedyArg = true)]
  55. public void CMD_UserRegistration(Client player, string password)
  56. {
  57. var hash = BCr.BCrypt.HashPassword(password, BCr.BCrypt.GenerateSalt(12));
  58.  
  59. UserAccount account = new UserAccount
  60. {
  61. Username = player.name,
  62. Hash = hash
  63. };
  64.  
  65. _userRepository.RegisterAccount(account);
  66.  
  67. API.sendChatMessageToPlayer(player, "You're now registered!");
  68. }
  69.  
  70. }
  71.  
  72. public interface IUserRepository
  73. {
  74. UserAccount RegisterAccount(UserAccount userAccount);
  75. UserAccount GetAccount(string name);
  76. }
  77.  
  78. public class UserAccount
  79. {
  80. public string Username { get; set; }
  81. public string Hash { get; set; }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement