--- Dear Guru; I have a problem with the code below, the program runs fine with the following situation,
Lecturer Option 1- When user type in the " Login name", " Secret question" , " Secret answer" and choosing option as "Lecturer" . 2- The table name "Wusers" will called and selected where the loginame="Login name" 2-1 Loop (Display the form for the user input login name, secret question, secret answer again) 3-if match then compare "secretquestion","secretanswer", with the " Secret question", "Secret answer" that the user have entered. 4-If all matched then call the " New _password_form" , and the user have to enter the new-password two times, if all match then the new password which just entered by user will save into the Wusers table. 1- Loop (display New password_form again if not match) but my program not display the New_password_form again if the input of two password not match, however it instead display the Main_form, which is asked user to enter the login name, secret question, secret ansewer instead. Thank very. ------------------------------------------------------ Wusers secretquestion,secretanswer, loginame, password ---------------------------------------------------- #!/perl/bin/perl use strict; use warnings; use CGI qw( :standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use DBI; use users; use vars qw($error_message $color1 $color2 $color3 $error_password); ###################################################### my $sth= $dbh->prepare('SELECT userid from wusers'); $sth->execute(); my (@choose_course); while(my @us1=$sth->fetchrow_array){ push(@choose_course,$us1[0]); } ############################################### my $loginame=param('LOGIN_NAME'); my $secret_answer=param('SECRET_ANSWER'); my $secret_question=param('SECRET_QUESTION'); my $option=param('OPTION'); my $course=param('COURSE'); $color1="black"; $color2="black"; $color3="black"; if(param('FORGET_PASSWORD') && param('OPTION') eq "Lecturer") { my $lecturer_rec=$dbh->prepare("SELECT * FROM Wusers WHERE Loginame=?") or &dienice("Error"); $lecturer_rec->execute($loginame) or &dienice("Can not find the database, whether connection error or ..."); if(my $rec_lec=$lecturer_rec->fetchrow_hashref) { if($rec_lec->{secretquestion} ne $secret_question) { $error_message.="<font color=red>Please enter the secret question correctly!</font><p>"; $color2="red"; } if($rec_lec->{secretanswer} ne $secret_answer) { $error_message.="<font color=red>Please enter the serect answer correctly!</font><p>"; $color3="red"; } if($error_message eq "") { if(param('CREATE_NEW_PASSWORD')){ my $password1=param('NEW_PASSWORD1'); my $password2=param('NEW_PASSWORD2'); if((length(param('NEW_PASSWORD1')) < 6) || (length(param('NEW_PASSWORD2')) < 6 ) || (param('NEW_PASSWORD1') ne param('NEW_PASSWORD2'))) { $error_password="The passowrd doesnt mucht"; &new_password_form; } if($error_password eq "") { my $record_lecturer=do("UPDATE Wusers SET password='$password1' WHERE loginame='$loginame'"); &success; } else { $error_password="The"; &new_password_form; } } else { &new_password_form; } } else { &main_form; } } else { $color1="red"; $color2="red"; $color3="red"; $error_message= "<font color=red>Please enter your login name correctly, along with other information.</font><p>"; &main_form; } } elsif(param('FORGET_PASSWORD') && param('OPTION') eq "Student") { my $data_name="Student_table" ; my $student_rec=$dbh->prepare("SELECT * FROM $data_name WHERE loginame=? ") or &dienice("Cannot open the database"); $student_rec->execute($loginame) or &dienice("Cannot not retrieve the database!"); if(my $rec_stu=$student_rec->fetchrow_hashref) { if($rec_stu->{secretquestion} ne $secret_question) { $error_message.="<font color=red>Please enter the secret question correctly!</font><p>"; $color2="red"; } if($rec_stu->{secretanswer} ne $secret_answer) { $error_message.="<font color=red>Please enter the serect answer correctly!</font><p>"; $color3="red"; } if($error_message eq "") { &new_password_form; } else { &main_form; } } else { $color1="red"; $color2="red"; $color3="red"; $error_message= "<font color=red>Please enter your login name correctly, along with other information.</font><p>"; &main_form; } } else { &main_form; } ################################################################################# sub main_form { print header(-type=>'text/html'),start_html(-title=>'Forget password'),start_form(-method=>'post'),br(),br(), table({-border=>0,-cellspacing=>4, -cellpadding=>4, -bgcolor=>'#904444', -align=>'center'}, caption(strong('Please enter the following')), TR({-valign=>'top'}, [ th({-align=>'center'},u('Option')). td({-colspan=>3},radio_group(-name=>'OPTION', -values=>['Student','Lecturer'], -default=>'Student')). th(strong('Id'),popup_menu(-name=>'COURSE', -values=>[EMAIL PROTECTED])), th({-align=>'right'},font({-color=>$color1},"Login Name:")).td(textfield(-name=>'LOGIN_NAME', -size=>20, -maxlength=>25)), th({-align=>'right'},font({-color=>$color2},"Secret Question:")).td(textfield(-name=>'SECRET_QUESTION', -size=>40, -maxlength=>50)), th({-align=>'right'},font({-color=>$color3},"Secret Answer: ")).td(textfield(-name=>'SECRET_ANSWER', size=>40, -maxlength=>50)), td({-colspan=>2, -align=>'center'}, submit(-name=>'FORGET_PASSWORD',-value=>'Click to validate')), td({-colspan=>2, -align=>'center'}, $error_message) ] )),end_form(); } #################################################################################### sub new_password_form { print header(-type=>'text/html'),start_html(-title=>'creat new password'),start_form(-method=>'post'),br(),br(), hidden(-name=>'LOGIN_NAME' -value=>$loginame), hidden(-name=>'OPTION' -value=>$option), table({-border=>0,-cellspacing=>2, -cellpadding=>4, -bgcolor=>'#904444', -align=>'center'}, caption(strong('Create New Password')), TR({-valign=>'top'}, [ th({-align=>'right'},["Password:"]).td(password_field(-name=>'NEW_PASSWORD1', -size=>20, -maxlength=>25)), th({-align=>'right'},["re-enter:"]).td(password_field(-name=>'NEW_PASSWORD2', -size=>20, -maxlength=>25)), td({-colspan=>2}, submit(-name=>'CREATE_NEW_PASSWORD',-value=>'Create New Password')), td({-align=>'center'}, $error_password) ] )),end_form(); } ############################################################################# sub success { print header,start_html(-title=>'Congratulation'), h3('You have successfully changed the password!'), end_html; } May GOD blesses you, and your family ============================= _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs