Pincode

Posted on Wednesday 30th May 2007 at 07:41 PM
MCP
MCP's Avatar
Is there any way that the user may know their pincode without me using mySQL and PMing it to them? Cause the only way they can retrieve forgotten passwords is for them to identify themselves with username and pincode.
Posted on Wednesday 30th May 2007 at 08:41 PM
SkillMaster
SkillMaster's Avatar
Add it to the register.php ill whip up a code now and post it.
Posted on Wednesday 30th May 2007 at 08:45 PM
SkillMaster
SkillMaster's Avatar
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. echo "<center>";
  5. //checks if there trying to veriy there account
  6. if(isset($_GET['verify'])){
  7. //gets the code and makes it safe
  8. $code = addslashes($_GET['code']);
  9. //gets the code from the database
  10. $getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");
  11. //counts the number of rows
  12. $getcode = mysql_num_rows($getcode);
  13. //if the ammount of rows is 0 the code does not exist
  14. if ($getcode == 0)
  15. {
  16. echo "Invalid verification code!";
  17. }
  18. //or if the code does exist we will activiate there account
  19. else
  20. {
  21. //get the data from the database
  22. $getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");
  23. //fetchs the data from the db
  24. $dat = mysql_fetch_array($getcode);
  25. //sets the users user level to 2 which means they can now use there account
  26. $update = mysql_query("UPDATE `members` SET `userlevel` = '2' WHERE `username` = '".$dat['username']."'") or die(mysql_error());
  27. //deletes the code as there is no use of it now
  28. $delete = mysql_query("DELETE FROM `verification` WHERE code = '$code'");
  29. //says thanks and your account is ready for use
  30. echo "Thank you, Your account has been verified.";
  31. }
  32. }
  33. else
  34. //if we have posted the register for we will register this user
  35. if(isset($_GET['register'])){
  36. //check to see if any fields were left blank
  37. if((!$_POST[username]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST[email])|| (!$_POST[pincode])){
  38. echo "A field was left blank please go back and try again.";
  39. }
  40. else
  41. {
  42. //posts all the data from the register form
  43. $username = $_POST[username];
  44. $password = $_POST[password];
  45. $cpassword = $_POST[cpassword];
  46. $email = $_POST[email];
  47. $pincode = $_POST[pincode];
  48. //check see if the 2 passwords are the same
  49. if($password == $cpassword)
  50. {
  51. //encrypts the password 8 times
  52. $password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($password))))))));
  53. $cname = mysql_query("SELECT `username` FROM `members` WHERE `username` = '$username'");
  54. $cname= mysql_num_rows($cname);
  55. //checks to see if the username or email allready exist
  56. if ($cname>=1) {
  57. echo "The username is already in use";
  58. }
  59. else
  60. {
  61. //gets rid of bad stuff from there username and email
  62. $username = addslashes(htmlspecialchars($username));
  63. $email = addslashes(htmlspecialchars($email));
  64. $pincode = addslashes(htmlspecialchars($pincode));
  65. //adds them to the db
  66. $adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `pincode`) VALUES('$username','$password','$email','$pincode')");
  67. //posible letters for the verification code
  68. $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  69. //shuffles the letters around to create a 16 long code
  70. $code = substr(str_shuffle($alphanum), 0, 16);
  71. //adds there code along with there user name to the db
  72. $addcode = mysql_query("INSERT INTO `verification` (`username`, `code`) VALUES('$username','$code')");
  73. //don't edit this, this is the link for there activication
  74. $link = "https://$host$self?verify&code=$code";
  75. //sends the email to the person
  76. mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename.
  77. Please copy the below link into you address bar,
  78.  
  79. $link", "From: Site Verification");
  80. //message sent now lets tell them to check there email
  81. echo "You are now registered,<br><br>Please check your email to activate your account.";
  82. }
  83. }
  84. else
  85. {
  86. echo "Your password and conformation password do not match!";
  87. }
  88. }
  89. }
  90. else
  91. {
  92. //none of the above so lets show the register form
  93. echo "<form action='register.php?register' method='post'>
  94. <fieldset style='width: 350'>
  95. <table width='350'>
  96. <tr>
  97. <td width='150'>Username:</td>
  98. <td width='200'><input type='text' name='username' size='30' maxlength='25'></td>
  99. </tr>
  100. <tr>
  101. <td>Password:</td>
  102. <td><input type='password' name='password' size='30' maxlength='25'></td>
  103. </tr>
  104. <tr>
  105. <td>Confirm Password:</td>
  106. <td><input type='password' name='cpassword' size='30' maxlength='25'></td>
  107. </tr>
  108. <tr>
  109. <td>Email:</td>
  110. <td><input type='text' name='email' size='30' maxlength='55'></td>
  111. </tr>
  112. <tr>
  113. <tr>
  114. <td>Pincode:</td>
  115. <td><input type='text' name='pincode' size='30' maxlength='4'></td>
  116. </tr>
  117. <tr>
  118. <td colspan='2'><center><input type='submit' value='Register'></center></td>
  119. </tr>
  120. </table>
  121. </fieldset>
  122. </form>";
  123. }
  124. echo "<center>";
  125. ?

Try that, not tested so post error if you get.
Posted on Wednesday 30th May 2007 at 09:18 PM
Diablosblizz
Diablosblizz's Avatar
By pincode he means your Forgot Password tutorial. I suppose.

This will do the trick:

PHP Code
  1. <?php
  2. include('config.php');
  3. $getpin = mysql_query("GET pincode FROM members WHERE username = '$_POST[username]'");
  4.  
  5. echo "Your Pincode is $getpin";
  6. ?>


Not tested, try it and reply to see if it works.
Posted on Wednesday 30th May 2007 at 09:22 PM
SkillMaster
SkillMaster's Avatar
@Diablosblizz it would be.

PHP Code
  1. <?php
  2. include('config.php');
  3. $fetch = mysql_query("SELECT * FROM `members` where username = '$logged[username]');
  4. $getpin = mysql_fetch_array($fetch);
  5.  
  6. echo "Your Pincode is $getpin[pincode]";
  7. ?>
Posted on Wednesday 30th May 2007 at 09:22 PM
SkillMaster
SkillMaster's Avatar
@Diablosblizz it would be.

PHP Code
  1. <?php
  2. include('config.php');
  3. $fetch = mysql_query("SELECT * FROM `members` where username = '$logged[username]');
  4. $getpin = mysql_fetch_array($fetch);
  5.  
  6. echo "Your Pincode is $getpin[pincode]";
  7. ?>
Posted on Wednesday 30th May 2007 at 09:24 PM
Diablosblizz
Diablosblizz's Avatar
I don't see why you even need to fetch the array. Mysql should automatically do that, but, it doesn't.

That code will work above.
Posted on Wednesday 30th May 2007 at 10:18 PM
MCP
MCP's Avatar
I have got it working. Thanks for the help.
Posted on Thursday 31st May 2007 at 08:14 AM
SkillMaster
SkillMaster's Avatar
Its k its what were here for.
Posted on Friday 22nd June 2007 at 04:44 PM
Dean
Dean's Avatar
Topic Solved

- Locked -
Topic is locked