Guest User

Untitled

a guest
Oct 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #!C:/Perl64/bin/perl.exe
  2.  
  3. # -- INCLUDES -- #
  4.  
  5. use CGI;
  6. use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
  7. use Crypt::SaltedHash;
  8. use strict;
  9. use warnings;
  10. require 'dbconnect.pm';
  11.  
  12. # -- DECLARE VARIABLES AND SET INITIAL VALUES -- #
  13.  
  14. my ($error_message);
  15. my $form = CGI->new;
  16. my ($company) = uc( $form->param('company') );
  17. my ($contact) = uc( $form->param('contact') );
  18. my ($street1) = uc( $form->param('street1') );
  19. my ($street2) = uc( $form->param('street2') );
  20. my ($city) = uc( $form->param('city') );
  21. my ($state) = uc( $form->param('state') );
  22. my ($zip) = $form->param('zip');
  23. my ($phone1) = $form->param('phone1');
  24. my ($phone2) = $form->param('phone2');
  25. my ($email) = lc( $form->param('email') );
  26. my ($email2) = lc( $form->param('email2') );
  27. my ($password) = $form->param('password');
  28. my ($password2) = $form->param('password2');
  29. chomp(
  30. $company, $contact, $street1, $street2, $city,
  31. $state, $zip, $phone1, $phone2, $email,
  32. $email2, $password2, $password
  33. );
  34. my $salted = $password;
  35. my $secret = $contact;
  36.  
  37. # -- STRIP INVALID CHARACTERS FROM ENTRIES -- #
  38.  
  39. $company =~ s/[^a-zA-Z0-9\-\&\s]*//g;
  40. $contact =~ s/[^a-zA-Z\s]*//g;
  41. $street1 =~ s/[^a-zA-Z0-9\.\s]*//g;
  42. $street2 =~ s/[^a-zA-Z0-9\.\s]*//g;
  43. $city =~ s/[^a-zA-Z\s]*//g;
  44. $state =~ s/[^A-Z]*//g;
  45. $zip =~ s/[^0-9-]*//g;
  46. $phone1 =~ s/[^0-9]*//g;
  47. $phone2 =~ s/[^0-9]*//g;
  48. $email =~ s/[^a-zA-Z0-9\-\.\@]*//g;
  49.  
  50. # -- VALIDATE EMAIL AND PASSWORD ENTRIES -- #
  51.  
  52. sub isvaliddate {
  53.  
  54. if ( $email =~ /^(\w¦\-¦\_¦\.)+\@((\w¦\-¦\_)+\.)+[a-zA-Z]{2,}$/ ) {
  55. return 1;
  56. }
  57.  
  58. else {
  59. $error_message .=
  60. "The Email Address you entered is invalid. Emails should look like <i>Example\@host.net</i>. \n\n";
  61. return;
  62. }
  63.  
  64. if ( $email2 =~ /^(\w¦\-¦\_¦\.)+\@((\w¦\-¦\_)+\.)+[a-zA-Z]{2,}$/ ) {
  65. return 1;
  66. }
  67.  
  68. else {
  69. $error_message .=
  70. "The Email Address you entered is invalid. Emails should look like <i>Example\@host.net</i>. \n\n";
  71. return;
  72. }
  73.  
  74. if ( $email = $email2 ) {
  75. return 1;
  76. }
  77.  
  78. else {
  79. $error_message .=
  80. "Your email addresses don't match. Please verify them and resubmit the form. \n \n";
  81. return;
  82. }
  83.  
  84. if ( $password = $password2 ) {
  85. return 1;
  86. }
  87.  
  88. else {
  89. my $error_message .= "Your passwords do not match.";
  90. return;
  91. }
  92.  
  93. # -- Other IF statements go here for validating. -- #
  94. }
  95.  
  96. #-- SALT PASSWORD--#
  97. # ALGORITHMS: SHA-1, SHA256, SHA-384
  98.  
  99. my $csh = Crypt::SaltedHash->new( algorithm => 'SHA-1' );
  100. $csh->add($secret);
  101. my $salted = $csh->generate;
  102. my $valid = Crypt::SaltedHash->validate( $salted, $secret );
  103.  
  104. # -- PRINT CONTENT TYPE AND EXPORT TO BROWSER -- #
  105.  
  106. print "content-type: text/html \n\n";
  107.  
  108. if ( $error_message = '' ) {
  109.  
  110. print
  111. "Company: $company<br>Contact: $contact<br>Street1: $street1<br>Street2: $street2<br>City: $city<br>State: $state<br>Zip: $zip<br>Phone1: $phone1<br>Phone2: $phone2<br>Email: $email<br>Password: $password<br>Salted: $salted<br>Secret: $secret<br>Valid: ";
  112.  
  113. if ( $valid = '1' )
  114.  
  115. {
  116. print "True";
  117. }
  118.  
  119. else
  120.  
  121. {
  122. print "False";
  123. }
  124. }
  125.  
  126. else
  127.  
  128. {
  129. print qq~<h1>
  130. <font color="red">
  131. $error_message
  132. </font>
  133. </h1>
  134.  
  135. <form method="post" action="cgi-bin/compreg.pl">
  136.  
  137. <table>
  138. <tr>
  139. <td>
  140. Company Name: <input type="text" name="company" length="20" maxlength="50" value="$company">*
  141. </td>
  142.  
  143. <td>
  144. Contact Name: <input type="text" name="contact" length="20" maxlength="75" value="$contact">*
  145. </td>
  146. </tr>
  147. <tr>
  148. <td>
  149. Street Address: <input type="text" name="street1" length="20" maxlength="50" value="$street1">*
  150. </td>
  151. <td>
  152.  
  153. PO Box / Suite: <input type="text" name="street2" length="20" maxlength="50" value="$street2">
  154. </td>
  155. </tr>
  156. <tr>
  157. <td>
  158. City: <input type="text" name="city" length="20" maxlength="50" value="$city">*
  159. </td>
  160. <td>
  161.  
  162. State: <input type="text" name="state" length=20" maxlength="2" value="$state">*
  163. </td>
  164. </tr>
  165. <tr>
  166. <td>
  167. Zipcode: <input type="text" name="zip" length="20" maxlength="10" value="$zip">*
  168. </td>
  169. <td>
  170.  
  171.  
  172. </td>
  173. </tr>
  174. <tr>
  175. <td>
  176. Primary Phone: <input type="text" name="phone1" length="20" maxlength="10" value="$phone1">*
  177. </td>
  178. <td>
  179. Alternate Phone: <input type="text" name="phone2" length="20" maxlength="10" value="$phone2">
  180.  
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>
  185. Email: <input type="text" name="email" length="20" maxlength="50" value="$email">*<br>
  186. Verify: <input type="text" name="email2" length="20" maxlength="50" value="$email2">*
  187. </td>
  188. <td>
  189. Password: <input type="password" name="password" length="20" maxlength="20">*<br>
  190. Verify: <input type="password" name="password2" length="20" maxlength="20">*
  191.  
  192. </td>
  193. </tr>
  194. </table>
  195. <br>
  196. <input type="submit" value="Submit Application">
  197. </form>~;
  198. }
  199.  
  200. 1;
Add Comment
Please, Sign In to add comment