login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > JS > Beveiliging > Login script voor meerdere gebruikers!

Login script voor meerdere gebruikers!

Auteur: Robsdomein.nl - 04 oktober 2006 - 15:17 - Gekeurd door: Rens - Hits: 7894 - Aantal punten: 4.25 (6 stemmen)





Als je de code die hieronder staat in een html-document zet en het document dan opent zie je een tabel met allemaal namen.

Daaronder staat (in het engels) een uitleg, als je deze uitleg leest zul je weten hoe je een login-script moet maken voor meerdere gebruikers!

Code:
  1. <center><table border=1>
  2. <tr><form name=members><td rowspan=4>
  3. <select name=memlist size=10 onChange="showmem(this.form)">
  4. <!-- Original: Dion -->
  5. <!-- "member name | password | destination pagename |" -->
  6. <option selected value="John Smith|password|mainpage|">John Smith
  7. <option value="Peter Jones|theirpwd|endpages|">Peter Jones
  8. <option value="Sue Brown|asdfvcxz|nowheres|">Sue Brown
  9. <option value="Sally West|zaqxswde|logintop|">Sally West
  10. </select></td>
  11. <td align=right>User:</td><td><input type=hidden value="0" name=entry>
  12. <input type=text name=memname size=8 value=""></td></tr>
  13. <tr><td align=right>Password:</td><td><input type=text name=password size=8 maxlength=8><font size="-1"><-- Must be exactly 8 characters</font></td></tr>
  14. <tr><td align=right>Page Name:</td><td><input type=text name=pagename size=8 maxlength=8><b>.html</b><font size="-1"><-- Must be exactly 8 characters</font></td></tr>
  15. <tr><td colspan=2 align=center>
  16. <input type=button value="New User" onclick="addnew(this.form);">
  17. <input type=button value="Delete User" onclick="delthis(this.form);">
  18. <input type=button value="Update/Show Coding" onclick="update(this.form); create(this.form);"></td></tr>
  19. <tr><td colspan=3 align=center>
  20. <input type=text size=60 name=message value="Note: Password/Page Name must be exactly 8 letters! (a-z)">
  21. <input type=hidden name=num value=1></td>
  22. </form></tr>
  23. </table>
  24. <hr size=2 width=75%>
  25. <form name=js><textarea cols=75 rows=10 name=scrpt wrap=virtual>
  26. <SCRIPT LANGUAGE="JavaScript">
  27. <!-- Begin
  28. var params=new Array(4);
  29. var alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI";
  30. function check(form) {
  31. which=form.memlist.selectedIndex;
  32. choice = form.memlist.options[which].value+"|";
  33. if (choice=="x|") {
  34. alert("Please Select Your Name From The List");
  35. return;
  36. }
  37. p=0;
  38. for (i=0;i<3;i++) {
  39. a=choice.indexOf("|",p);
  40. params[i]=choice.substring(a,p);
  41. p=a+1;
  42. }
  43. h1=makehash(form.pass.value,3);
  44. h2=makehash(form.pass.value,10)+" ";
  45. if (h1!=params[1]) {
  46. alert("Incorrect Password!"); return; };
  47. var page="";
  48. for (var i=0;i<8;i++) {
  49. letter=params[2].substring(i,i+1)
  50. ul=letter.toUpperCase();
  51. a=alpha.indexOf(ul,0);
  52. a-=(h2.substring(i,i+1)*1);
  53. if (a<0) a+=26;
  54. page+=alpha.substring(a,a+1); };
  55. top.location=page.toLowerCase()+".html";
  56. }
  57. function makehash(pw,mult) {
  58. pass=pw.toUpperCase();
  59. hash=0;
  60. for (i=0;i<8;i++) {
  61. letter=pass.substring(i,i+1);
  62. c=alpha.indexOf(letter,0)+1;
  63. hash=hash*mult+c;
  64. }
  65. return(hash);
  66. }
  67. // End -->
  68. </script>
  69. </textarea>
  70. </form>
  71. <SCRIPT LANGUAGE="JavaScript">
  72. <!-- Begin
  73. var params=new Array(4);
  74. var script=document.js.scrpt.value;
  75. document.js.scrpt.value="Create your users, their passwords, and their destination pages using the form above.\n\nThen, click 'Show Coding' to see the login HTML and JavaScript that you need to put on your page to password-protect your site with that info.\n\nQuestions about this script or how to put it on your site should be directed to it's author via email: dion@mailhub.omen.com.au\n\n*Honestly, we don't even totally understand this JavaScript!*";
  76. var alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI";
  77. showmem(document.members);
  78. function showmem(form) {
  79. document.members.num.value=document.members.memlist.length;
  80. var which=form.memlist.selectedIndex;
  81. splt(form.memlist[which].value);
  82. form.entry.value=which+1;
  83. for (i=2;i<5;i++) {
  84. form.elements[i].value=params[i-2]; };
  85. }
  86. function splt(choice) {
  87. p=0;
  88. for (i=0;i<3;i++) {
  89. a=choice.indexOf("|",p);
  90. params[i]=choice.substring(a,p);
  91. p=a+1;
  92. }
  93. }
  94. function addnew(form) {
  95. newmem=getfields(form);
  96. var who=prompt("New User's Name:","");
  97. form.memlist[form.memlist.length] = new Option(who, newmem, false, true);
  98. if (navigator.appName=="Netscape") {
  99. document.js.scrpt.value=script;
  100. history.go(0);
  101. }
  102. else {
  103. showmem(document.members);
  104. }
  105. }
  106. function getfields(form) {
  107. newmem="";
  108. for (i=2;i<5;i++) {
  109. newmem+=form.elements[i].value+"|"; };
  110. for (i=3;i<5;i++) {
  111. a=form.elements[i];
  112. for (k=0;k<8;k++) {
  113. }
  114. }
  115. return(newmem);
  116. }
  117. function delthis(form) {
  118. if (confirm("Delete "+form.memname.value+"?")) {
  119. form.memlist.options[form.entry.value-1]=null;
  120. form.message.value=form.memname.value+" Deleted";
  121. form.memlist.selectedIndex=0;
  122. if (navigator.appName=="Netscape") {
  123. document.js.scrpt.value=script;
  124. history.go(0);
  125. }
  126. else {
  127. showmem(document.members);
  128. }
  129. }
  130. }
  131. function update(form) {
  132. msg="no";
  133. a=form.elements[i];
  134. for (k=0;k<8;k++) {
  135. b=a.value.substring(k,k+1);
  136. c=b.toUpperCase();
  137. form.memlist[form.entry.value-1].value=getfields(form);
  138. form.message.value=form.memname.value+"'s record was updated";
  139. }
  140. }
  141. function create(form) {
  142.  
  143. var html="<center><form name=login>\n";
  144. html+="<table border=1 cellpadding=3>\n\n";
  145. html+="&lt;!-- Original: Dion --&gt;\n";
  146. html+="<!-- Web Site: http://www.iinet.net.au/~biab/ --&gt;\n";
  147. html+="<!-- This script and many more are available free online at --&gt;\n";
  148. html+="<!-- Robs Web!! http://www.robsdomein.nl --&gt;\n\n";
  149. html+='<tr><td colspan=2 align=center><font size="+2">';
  150. html+='<b>Members-Only Area!</b></font></td></tr>\n';
  151. html+="<tr><td>Username:</td><td><select name=memlist>\n<option value='x'>";
  152. for (j=0;j<form.memlist.length;j++) {
  153. splt(form.memlist.options[j].value);
  154. h1=makehash(params[1],3);
  155. h2=makehash(params[1],10)+" ";
  156. var page="";
  157. for (var i=0;i<8;i++) {
  158. letter=params[2].substring(i,i+1);
  159. ul=letter.toUpperCase();
  160. a=alpha.indexOf(ul,0);
  161. a+=(h2.substring(i,i+1)*1);
  162. page+=alpha.substring(a,a+1);
  163. }
  164. html+="\n<option value='"+params[0]+"|"+h1+"|"+page+"'>"+params[0];
  165. };
  166. html+="\n</select></td></tr>\n";
  167. html+="<tr><td>Password:</td><td><input type=password size=10 maxlength=8 name=pass></td></tr>\n";
  168. html+='<tr><td colspan=2 align=center><input type=button value="Login" onclick="check(this.form)"></td>\n';
  169. html+="</tr>\n</table>\n</form>\n";
  170. document.js.scrpt.value=html+script+"</center>";
  171. }
  172. function makehash(pw,mult) {
  173. pass=pw.toUpperCase();
  174. hash=0;
  175. for (i=0;i<8;i++) {
  176. letter=pass.substring(i,i+1);
  177. c=alpha.indexOf(letter,0)+1;
  178. hash=hash*mult+c;
  179. }
  180. return(hash);
  181. }
  182. // End -->
  183. </script>
  184. </center>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (10)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.035s