473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

my script not running and i need help

i have two scripts that are not running to reset a password that has been forgotten and the other to change old password.

here are the scripts.

change_passwd.php
[PHP]
session_start();
do_html_header("Changing password");
//check_valid_user();
$new_passwd=($_POST['new_passwd']);
$new_passwd2=($_POST['new_passwd2']);
if (!filled_out($HTTP_POST_VARS))
{
echo "You have not filled out the form completely.
Please try again.";
display_user_menu();
//do_html_footer();
exit;
}
else
{
if ($new_passwd!=$new_passwd2)
echo "Passwords entered were not the same. Not changed.";
else if (strlen($new_passwd)>16 || strlen($new_passwd)<6)
echo "New password must be between 6 and 16 characters. Try again.";
else
{
// attempt update
if (change_password($valid_user, $old_passwd, $new_passwd))
echo "Password changed.";
else
echo "Password could not be changed.";
}


}
display_user_menu();
//do_html_footer();[/PHP]

error warnings from this code are.

Notice: Undefined index: new_passwd in C:\project\test\change_passwd.php on line 6

Notice: Undefined index: new_passwd2 in C:\project\test\change_passwd.php on line 7
New password must be between 6 and 16 characters. Try again.
Fatal error: Call to undefined function: display_user_menu() in C:\project\test\change_passwd.php on line 33

[PHP]
function change_password($username, $old_passwd, $new_passwd)
// change password for username/old_password to new_password
// return true or false
{
// if the old password is right
// change their password to new_password and return true
// else return false
if (login($username, $old_passwd))
{
if (!($conn = db_connect()))
return false;
$result = mysql_query( "update users
set passwd = password('$new_passwd')
where username = '$username'");
if (!$result)
return false; // not changed
else
return true; // changed successfully
}
else
return false; // old password was wrong
}

function get_random_word($min_length, $max_length)
// grab a random word from dictionary between the two lengths
// and return it
{
// generate a random word
$word = "";
$dictionary = "/usr/share/dict/words"; // the ispell dictionary
$fp = fopen($dictionary, "r");
$size = filesize($dictionary);

// go to a random location in dictionary
srand ((double) microtime() * 1000000);
$rand_location = rand(0, $size);
fseek($fp, $rand_location);

// get the next whole word of the right length in the file
while (strlen($word)< $min_length || strlen($word)>$max_length)
{
if (feof($fp))
fseek($fp, 0); // if at end, go to start
$word = fgets($fp, 80); // skip first word as it could be partial
$word = fgets($fp, 80); // the potential password
};
$word=trim($word); // trim the trailing \n from fgets
return $word;
}
function reset_password($username)
// set password for username to a random value
// return the new password or false on failure
{
// get a random dictionary word b/w 6 and 13 chars in length
$new_passwd = get_random_word(6, 13);

// add a number between 0 and 999 to it
// to make it a slightly better password
srand ((double) microtime() * 1000000);
$rand_number = rand(0, 999);
$new_passwd .= $rand_number;

// set user's password to this in database or return false
if (!($conn = db_connect()))
return false;
$result = mysql_query( "update users
set passwd = password('$new_password')
where username = '$username'");
if (!$result)
return false; // not changed
else
return $new_passwd; // changed successfully
}

function notify_password($username, $passwd)
// notify the user that their password has been changed
{
if (!($conn = db_connect()))
return false;
$result = mysql_query("select email from users
where username='$username'");
if (!$result)
return false; // not changed
else if (mysql_num_rows($result)==0)
return false; // username not in db
else
{
$email = mysql_result($result, 0, "email");
$from = "From: support@learning_system \r\n";
$mesg = "Your password has been changed to $password \r\n"
."Please change it next time you log in. \r\n";
if (mail($email, "Learning System login information", $mesg, $from))
return true;
else
return false;
}
}[/PHP]

hese are the errror warnings i got.

Warning: fopen(/usr/share/dict/words) [function.fopen]: failed to open stream: No such file or directory in C:\project\test\user_auth_fns.php on line 99

Warning: filesize() [function.filesize]: Stat failed for /usr/share/dict/words (errno=2 - No such file or directory) in C:\project\test\user_auth_fns.php on line 100

Warning: fseek(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 105

Warning: feof(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 110

Warning: fgets(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 112

Warning: fgets(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 113

------------------------------------------------------------------------------------------------------------------

yo help is greatly appreciated.
Feb 14 '07 #1
2 2082
cassbiz
202 100+
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password.

here are the scripts.

change_passwd.php
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. do_html_header("Changing password");
  3. //check_valid_user();
  4. $new_passwd=($_POST['new_passwd']);
  5. $new_passwd2=($_POST['new_passwd2']);
  6. if (!filled_out($HTTP_POST_VARS))
  7. {
  8. echo "You have not filled out the form completely.
  9. Please try again.";
  10. display_user_menu();
  11. //do_html_footer(); 
  12. exit;
  13. }
  14. else 
  15. {
  16. if ($new_passwd!=$new_passwd2)
  17. echo "Passwords entered were not the same. Not changed.";
  18. else if (strlen($new_passwd)>16 || strlen($new_passwd)<6)
  19. echo "New password must be between 6 and 16 characters. Try again.";
  20. else
  21. {
  22. // attempt update
  23. if (change_password($valid_user, $old_passwd, $new_passwd))
  24. echo "Password changed.";
  25. else
  26. echo "Password could not be changed.";
  27. }
  28.  
  29.  
  30. }
  31. display_user_menu(); 
  32. //do_html_footer();[/PHP]
  33.  
  34. error warnings from this code are.
  35.  
  36. Notice: Undefined index: new_passwd in C:\project\test\change_passwd.php on line 6
  37.  
  38. Notice: Undefined index: new_passwd2 in C:\project\test\change_passwd.php on line 7
  39. New password must be between 6 and 16 characters. Try again.
  40. Fatal error: Call to undefined function: display_user_menu() in C:\project\test\change_passwd.php on line 33
  41.  
  42. [PHP]
  43. function change_password($username, $old_passwd, $new_passwd)
  44. // change password for username/old_password to new_password
  45. // return true or false
  46. {
  47. // if the old password is right 
  48. // change their password to new_password and return true
  49. // else return false
  50. if (login($username, $old_passwd))
  51. {
  52. if (!($conn = db_connect()))
  53. return false;
  54. $result = mysql_query( "update users
  55. set passwd = password('$new_passwd')
  56. where username = '$username'");
  57. if (!$result)
  58. return false; // not changed
  59. else
  60. return true; // changed successfully
  61. }
  62. else
  63. return false; // old password was wrong
  64. }
  65.  
  66. function get_random_word($min_length, $max_length)
  67. // grab a random word from dictionary between the two lengths
  68. // and return it
  69. {
  70. // generate a random word
  71. $word = "";
  72. $dictionary = "/usr/share/dict/words"; // the ispell dictionary
  73. $fp = fopen($dictionary, "r");
  74. $size = filesize($dictionary);
  75.  
  76. // go to a random location in dictionary
  77. srand ((double) microtime() * 1000000);
  78. $rand_location = rand(0, $size);
  79. fseek($fp, $rand_location);
  80.  
  81. // get the next whole word of the right length in the file
  82. while (strlen($word)< $min_length || strlen($word)>$max_length) 
  83. if (feof($fp)) 
  84. fseek($fp, 0); // if at end, go to start
  85. $word = fgets($fp, 80); // skip first word as it could be partial
  86. $word = fgets($fp, 80); // the potential password
  87. };
  88. $word=trim($word); // trim the trailing \n from fgets
  89. return $word; 
  90. }
  91. function reset_password($username)
  92. // set password for username to a random value
  93. // return the new password or false on failure
  94. // get a random dictionary word b/w 6 and 13 chars in length
  95. $new_passwd = get_random_word(6, 13);
  96.  
  97. // add a number between 0 and 999 to it
  98. // to make it a slightly better password
  99. srand ((double) microtime() * 1000000);
  100. $rand_number = rand(0, 999); 
  101. $new_passwd .= $rand_number;
  102.  
  103. // set user's password to this in database or return false
  104. if (!($conn = db_connect()))
  105. return false;
  106. $result = mysql_query( "update users
  107. set passwd = password('$new_password')
  108. where username = '$username'");
  109. if (!$result)
  110. return false; // not changed
  111. else
  112. return $new_passwd; // changed successfully 
  113. }
  114.  
  115. function notify_password($username, $passwd)
  116. // notify the user that their password has been changed
  117. {
  118. if (!($conn = db_connect()))
  119. return false;
  120. $result = mysql_query("select email from users
  121. where username='$username'");
  122. if (!$result)
  123. return false; // not changed
  124. else if (mysql_num_rows($result)==0)
  125. return false; // username not in db
  126. else
  127. {
  128. $email = mysql_result($result, 0, "email");
  129. $from = "From: support@learning_system \r\n";
  130. $mesg = "Your password has been changed to $password \r\n"
  131. ."Please change it next time you log in. \r\n";
  132. if (mail($email, "Learning System login information", $mesg, $from))
  133. return true; 
  134. else
  135. return false; 
  136. }
  137. }
hese are the errror warnings i got.

Warning: fopen(/usr/share/dict/words) [function.fopen]: failed to open stream: No such file or directory in C:\project\test\user_auth_fns.php on line 99

Warning: filesize() [function.filesize]: Stat failed for /usr/share/dict/words (errno=2 - No such file or directory) in C:\project\test\user_auth_fns.php on line 100

Warning: fseek(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 105

Warning: feof(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 110

Warning: fgets(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 112

Warning: fgets(): supplied argument is not a valid stream resource in C:\project\test\user_auth_fns.php on line 113

------------------------------------------------------------------------------------------------------------------

yo help is greatly appreciated.
I will try to help here, but I myself am not an expert.

In regards to your dictionary, check your path to make sure that it is indeed there. Since I have not done any php on a Windows box I noticed that you are calling the dictionary with the forward slash /

$HTTP_POST_VARS should be be $_POST

That is all I see right now.

Good Luck
Feb 14 '07 #2
I will try to help here, but I myself am not an expert.

In regards to your dictionary, check your path to make sure that it is indeed there. Since I have not done any php on a Windows box I noticed that you are calling the dictionary with the forward slash /

$HTTP_POST_VARS should be be $_POST

That is all I see right now.

Good Luck
Its true that there is need to check the path but however it seems as if that Windows does not support the dictionary so I'm trying to down it but seems not to be working.I would appreciate if you can help me alternatively to come up with a function that generates a new password.
Feb 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I am currently running PHP 4.3.2 on Windows NT 4.0. Is there anyway (I am sure there is but I just can't find it) that you can determine the path of the current script that is running?...
5
by: Boris Nikolaevich | last post by:
This is backwards of what I usually want--normally if you have a long-running ASP script, it's a good idea to check to see whether the client is still connected so you can cancel execution. ...
10
by: Larry Neylon | last post by:
Hi All, I want to perform the simple task of running an ASP script as a scheduled job. Previously I've always either run a .vbs script via windows Scheduler, or put some logic in my...
10
by: Nimit | last post by:
Hi, I wasn't sure which forum this post belongs to, so I've posted it to a couple forums that I thought may be appropriate. In giving me advice, please consider me a beginner. Below is a synopsis...
10
by: shumaker | last post by:
I don't need a detailed description of a solution(although I wouldn't mind), but I am hoping someone could tell me in general the best path to go about accomplishing a task, since I don't know all...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
8
by: gupta24 | last post by:
i am in critical position please help we have machines a,b,c,d in each machine application servers are running but each machine have 40 application server are running result of 40 application...
1
by: sverkaik | last post by:
I have a PHP script which needs to run some other PHP scripts from within it. I need them to be executed on a timed basis, say, every minute. However, they can take a little while to run, and I do...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.