Guest User

Secure My Account - Beta 0.01

a guest
May 9th, 2016
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.04 KB | None | 0 0
  1. // Secure My Account - Beta 0.01
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <mysql>
  8. #define GOLD_COL               "{E5C100}"
  9. #define function%0(%1) forward%0(%1);public%0(%1)
  10. // db
  11. #define     SQL_HOST                    ""
  12. #define     SQL_USER                    ""
  13. #define     SQL_DB                      ""
  14. #define     SQL_PASS                    ""
  15.  
  16. public OnFilterScriptInit()
  17. {
  18.     mysql_init();
  19.     mysql_connect(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
  20.     return 1;
  21. }
  22. public OnFilterScriptExit()
  23. {
  24. return 1;
  25. }
  26. CMD:securemyaccount(playerid,params[])
  27. {
  28.  
  29.     Call_SecureMyAccount(playerid);
  30.  
  31.     return 1;
  32. }
  33.  
  34. forward Call_SecureMyAccount(playerid);
  35. public Call_SecureMyAccount(playerid)
  36. {
  37.     new query[400];
  38.     new string[128];
  39.     new random_code[6];
  40.     Random_Code(random_code, 6);
  41.     format(query, sizeof(query),"SELECT * FROM `codes` WHERE `code` = '%s' LIMIT 1", random_code);
  42.     mysql_query(query);
  43.     mysql_store_result();
  44.     new rows = mysql_num_rows();
  45.     if(rows == 1)
  46.     {
  47.         Call_SecureMyAccount(playerid);
  48.         return 1;
  49.     }
  50.     new uquery[200];
  51.     format(uquery, sizeof(uquery),"DELETE FROM `codes` WHERE user='%s'", PlayerName(playerid));
  52.     mysql_query(uquery);
  53.     new bquery[200];
  54.     new string_1[64];
  55.     new Year, Month, Day;
  56.     getdate(Year, Month, Day);
  57.     format(string_1, sizeof(string_1), "%02d/%02d/%d", Day, Month, Year);
  58.     format(string,sizeof(string),""GOLD_COL"Server:{FFFFFF} Your new account security access code is: {AFAFAF}%s{FFFFFF}!",random_code);
  59.     SendClientMessage(playerid,0xFFFFFFAA,string);
  60.     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please do NOT lose this code or you will not be able to log in.");
  61.     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please screen shot this code in case you won't remember.");
  62.     format(bquery, sizeof(bquery),"INSERT INTO admincodes(admin, code, date_generated) VALUES('%s', '%s', '%s')", PlayerName(playerid),random_code, string_1);
  63.     mysql_query(bquery);
  64.     mysql_free_result();
  65.     return 1;
  66. }
  67. PlayerName(playerid)
  68. {
  69.     new CName[24];
  70.     GetPlayerName(playerid, CName, 24);
  71.     return CName;
  72. }
  73.  
  74.  Random_Code(strDest[], strLen = 6)
  75. {
  76.     while(strLen--)
  77.         strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'a')) : (random(10) + '0');
  78. }
  79.  
  80. // USAGE EXAMPLE//
  81. /*
  82. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  83. {
  84.     switch(dialogid)
  85.     {
  86.         case DIALOG_REGISTER:
  87.         {
  88.             if (response == 0)
  89.             {
  90.                 SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} You must register before playing on this server.");
  91.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  92.                 return 1;
  93.             }
  94.             if (response == 1)
  95.             {
  96.                 if (strlen(inputtext)==0)
  97.                 {
  98.                     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please enter a password in the box below.");
  99.                     ShowRegisterScreen(playerid);
  100.                     return 1;
  101.                 }
  102.                 if(strlen(inputtext) < 4 || strlen(inputtext) > 34)
  103.                 {
  104.                     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please enter a password between 4-34 characters in the box.");
  105.                     ShowRegisterScreen(playerid);
  106.                     return 1;
  107.                 }
  108.                 new stringdate[200];
  109.                 new Year, Month, Day;
  110.                 getdate(Year, Month, Day);
  111.                 format(stringdate, sizeof(stringdate), "%02d/%02d/%d",Day, Month, Year);
  112.                 SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server: {FFFFFF}Please wait while the system creates and stores your account into the Database!");
  113.                 SetTimerEx("ShowLoginScreen_Reg",1000,false,"i",playerid);
  114.                 new pIp[16];
  115.                 PlayerPlaySound(playerid,5205,0.0,0.0,0.0);
  116.                 GetPlayerIp(playerid, pIp, sizeof(pIp));
  117.                 mysql_real_escape_string(inputtext, HashPass);
  118.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  119.                 format(Query, sizeof(Query), "INSERT INTO `zaplayerinfo` (`user`, `password`, `xp`, `kills`, `deaths`, `rank`, `adminlevel`, `viplevel`, `adminduty`, `hour`, `min`, `sec`, `mapsplayed`, `coins`, `banned`, `cleader`, `cmember`, `bans`, `reg_IP`, `regdate`) VALUES\
  120.                 ('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '%s', '%s')", escpname(playerid), HashPass, pIp, stringdate);
  121.                 mysql_query(Query);
  122.                 mysql_store_result();
  123.                 return true;
  124.             }
  125.             return 1;
  126.         }
  127.         case DIALOG_LOGIN:
  128.         {
  129.             if (response == 0)
  130.             {
  131.                 SendClientMessage(playerid,0xFFFFFFAA,""ADMIN_COL"OutBreak:{FFFFFF} You must login before playing on this server.");
  132.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  133.                 return 1;
  134.             }
  135.             if (response == 1)
  136.             {
  137.                 mysql_real_escape_string(inputtext, HashPass);
  138.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  139.                 if(!strcmp(HashPass, MyPassword))
  140.                 {
  141.                     format(Query, sizeof(Query), "SELECT * FROM `zaplayerinfo` WHERE `user` = '%s' AND `password` = '%s'", escpname(playerid), HashPass);
  142.                     mysql_query(Query);
  143.                     mysql_store_result();
  144.                     if(mysql_num_rows() > 0)
  145.                     {
  146.                         format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s' LIMIT 1", escpname(playerid));
  147.                         mysql_query(Query);
  148.                         mysql_store_result();
  149.                         if(mysql_num_rows() > 0)
  150.                         {
  151.                             ShowSecurityScreen(playerid);
  152.                             return 1;
  153.                         }
  154.                         MySQL_Login(playerid);
  155.                         return 1;
  156.                     }
  157.                 }
  158.                 ShowLoginScreen(playerid);
  159.                 return 1;
  160.             }
  161.             return 1;
  162.         }
  163.         case DIALOG_UserSECURITY:
  164.         {
  165.             if (response == 0)
  166.             {
  167.                 SendClientMessage(playerid,0xFFFFFFAA,""ADMIN_COL"OutBreak:{FFFFFF} You must enter your security access code before playing on this server.");
  168.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  169.                 return 1;
  170.             }
  171.             if (response == 1)
  172.             {
  173.                 format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s'", PlayerName(playerid));
  174.                 mysql_query(Query);
  175.                 mysql_store_result();
  176.                 if(mysql_num_rows() <= 0)
  177.                 {
  178.                     Kick(playerid);
  179.                 }
  180.                 new random_code_string[24];
  181.                 mysql_real_escape_string(inputtext,random_code_string);
  182.                 format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s' AND `code` = '%s'", PlayerName(playerid),random_code_string);
  183.                 mysql_query(Query);
  184.                 mysql_store_result();
  185.                 //if(!strcmp(code_string, random_code_entry))
  186.                 //{
  187.                 //    if(mysql_num_rows() > 0)
  188.                 //  {
  189.                 if(mysql_num_rows() == 1)
  190.                 {
  191.                     MySQL_Login(playerid);
  192.                     return 1;
  193.                 }
  194.                 //  }
  195.                 //}
  196.                 ShowSecurityScreen(playerid);
  197.                 return 1;
  198.             }
  199.             return 1;
  200.         }
  201. ShowSecurityScreen(playerid)
  202. {
  203.     new string[184];
  204.     format(string,sizeof(string),""ADMIN_COL"OutBreak:{FFFFFF} Security Check!");
  205.     ShowPlayerDialog(playerid, DIALOG_ADMINSECURITY, DIALOG_STYLE_PASSWORD,string,"Please enter your security 6 digit access code in order to login.","Enter","Quit");
  206.     return 1;
  207. }*/
Advertisement
Add Comment
Please, Sign In to add comment