Advertisement
Guest User

Secure My Account - Beta 0.2

a guest
Jun 4th, 2016
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.17 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.     EscapeString();
  66.     return 1;
  67. }
  68. PlayerName(playerid)
  69. {
  70.     new CName[24];
  71.     GetPlayerName(playerid, CName, 24);
  72.     return CName;
  73. }
  74.  
  75.  Random_Code(strDest[], strLen = 6)
  76. {
  77.     while(strLen--)
  78.         strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'a')) : (random(10) + '0');
  79. }
  80. EscapeString(const string[])
  81. {
  82.     new escape[128];
  83.     mysql_real_escape_string(string, escape);
  84.     return escape;
  85. }
  86. // USAGE EXAMPLE//
  87. /*
  88. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  89. {
  90.     switch(dialogid)
  91.     {
  92.         case DIALOG_REGISTER:
  93.         {
  94.             if (response == 0)
  95.             {
  96.                 SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} You must register before playing on this server.");
  97.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  98.                 return 1;
  99.             }
  100.             if (response == 1)
  101.             {
  102.                 if (strlen(inputtext)==0)
  103.                 {
  104.                     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please enter a password in the box below.");
  105.                     ShowRegisterScreen(playerid);
  106.                     return 1;
  107.                 }
  108.                 if(strlen(inputtext) < 4 || strlen(inputtext) > 34)
  109.                 {
  110.                     SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server:{FFFFFF} Please enter a password between 4-34 characters in the box.");
  111.                     ShowRegisterScreen(playerid);
  112.                     return 1;
  113.                 }
  114.                 new stringdate[200];
  115.                 new Year, Month, Day;
  116.                 getdate(Year, Month, Day);
  117.                 format(stringdate, sizeof(stringdate), "%02d/%02d/%d",Day, Month, Year);
  118.                 SendClientMessage(playerid,0xFFFFFFAA,""GOLD_COL"Server: {FFFFFF}Please wait while the system creates and stores your account into the Database!");
  119.                 SetTimerEx("ShowLoginScreen_Reg",1000,false,"i",playerid);
  120.                 new pIp[16];
  121.                 PlayerPlaySound(playerid,5205,0.0,0.0,0.0);
  122.                 GetPlayerIp(playerid, pIp, sizeof(pIp));
  123.                 mysql_real_escape_string(inputtext, HashPass);
  124.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  125.                 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\
  126.                 ('%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);
  127.                 mysql_query(Query);
  128.                 mysql_store_result();
  129.                 return true;
  130.             }
  131.             return 1;
  132.         }
  133.         case DIALOG_LOGIN:
  134.         {
  135.             if (response == 0)
  136.             {
  137.                 SendClientMessage(playerid,0xFFFFFFAA,""ADMIN_COL"OutBreak:{FFFFFF} You must login before playing on this server.");
  138.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  139.                 return 1;
  140.             }
  141.             if (response == 1)
  142.             {
  143.                 mysql_real_escape_string(inputtext, HashPass);
  144.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  145.                 if(!strcmp(HashPass, MyPassword))
  146.                 {
  147.                     format(Query, sizeof(Query), "SELECT * FROM `zaplayerinfo` WHERE `user` = '%s' AND `password` = '%s'", escpname(playerid), HashPass);
  148.                     mysql_query(Query);
  149.                     mysql_store_result();
  150.                     if(mysql_num_rows() > 0)
  151.                     {
  152.                         format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s' LIMIT 1", escpname(playerid));
  153.                         mysql_query(Query);
  154.                         mysql_store_result();
  155.                         if(mysql_num_rows() > 0)
  156.                         {
  157.                             ShowSecurityScreen(playerid);
  158.                             return 1;
  159.                         }
  160.                         MySQL_Login(playerid);
  161.                         return 1;
  162.                     }
  163.                 }
  164.                 ShowLoginScreen(playerid);
  165.                 return 1;
  166.             }
  167.             return 1;
  168.         }
  169.         case DIALOG_UserSECURITY:
  170.         {
  171.             if (response == 0)
  172.             {
  173.                 SendClientMessage(playerid,0xFFFFFFAA,""ADMIN_COL"OutBreak:{FFFFFF} You must enter your security access code before playing on this server.");
  174.                 SetTimerEx("KickPlayer",700,false,"i",playerid);
  175.                 return 1;
  176.             }
  177.             if (response == 1)
  178.             {
  179.                 format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s'", PlayerName(playerid));
  180.                 mysql_query(Query);
  181.                 mysql_store_result();
  182.                 if(mysql_num_rows() <= 0)
  183.                 {
  184.                     Kick(playerid);
  185.                 }
  186.                 new random_code_string[24];
  187.                 mysql_real_escape_string(inputtext,random_code_string);
  188.                 format(Query, sizeof(Query), "SELECT * FROM `codes` WHERE `user` = '%s' AND `code` = '%s'", PlayerName(playerid),random_code_string);
  189.                 mysql_query(Query);
  190.                 mysql_store_result();
  191.                 //if(!strcmp(code_string, random_code_entry))
  192.                 //{
  193.                 //    if(mysql_num_rows() > 0)
  194.                 //  {
  195.                 if(mysql_num_rows() == 1)
  196.                 {
  197.                     MySQL_Login(playerid);
  198.                     return 1;
  199.                 }
  200.                 //  }
  201.                 //}
  202.                 ShowSecurityScreen(playerid);
  203.                 return 1;
  204.             }
  205.             return 1;
  206.         }
  207. ShowSecurityScreen(playerid)
  208. {
  209.     new string[184];
  210.     format(string,sizeof(string),""ADMIN_COL"OutBreak:{FFFFFF} Security Check!");
  211.     ShowPlayerDialog(playerid, DIALOG_ADMINSECURITY, DIALOG_STYLE_PASSWORD,string,"Please enter your security 6 digit access code in order to login.","Enter","Quit");
  212.     return 1;
  213. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement