diff options
| author | Max Christian Pohle | 2016-10-15 19:20:18 +0200 |
|---|---|---|
| committer | Max Christian Pohle | 2016-10-15 19:20:18 +0200 |
| commit | 87c69016c5e7458df84950ae4eb0b5833262a370 (patch) | |
| tree | 13764a5364953fb1973db3abc1446cb177f17ab5 | |
| download | auth-form-alt-master.tar.bz2 auth-form-alt-master.zip | |
It basically works
| -rw-r--r-- | htaccess-sample | 15 | ||||
| -rw-r--r-- | htusers-sample | 12 | ||||
| -rw-r--r-- | login.html | 136 |
3 files changed, 163 insertions, 0 deletions
diff --git a/htaccess-sample b/htaccess-sample new file mode 100644 index 0000000..dabf6a9 --- /dev/null +++ b/htaccess-sample | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | # this file must be named .htaccess | ||
| 2 | DirectoryIndex login.html | ||
| 3 | |||
| 4 | AuthType Basic | ||
| 5 | AuthName "Password Protected Area" | ||
| 6 | AuthUserFile .htusers | ||
| 7 | Require valid-user | ||
| 8 | |||
| 9 | # allow only the root directory (=login.html, see above) to be shown... | ||
| 10 | SetEnvIf Request_URI ^/$ noauth=1 | ||
| 11 | Satisfy any | ||
| 12 | order deny,allow | ||
| 13 | deny from all | ||
| 14 | Allow from env=noauth | ||
| 15 | |||
diff --git a/htusers-sample b/htusers-sample new file mode 100644 index 0000000..dd91cf9 --- /dev/null +++ b/htusers-sample | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # this file should contain combinations of usernames and passwords, divided by colons and separated | ||
| 2 | # by newlines: | ||
| 3 | # | ||
| 4 | # user1:password2 | ||
| 5 | # user2:password2 | ||
| 6 | # | ||
| 7 | # the passwords must not be inserted as plain text, but as hashes. To generate these hashes one can | ||
| 8 | # use: | ||
| 9 | # openssl passwd -crypt password1 | ||
| 10 | # | ||
| 11 | # lines starting with # are not recognized and can be used as comments | ||
| 12 | |||
diff --git a/login.html b/login.html new file mode 100644 index 0000000..627308e --- /dev/null +++ b/login.html | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | <!DOCTYPE html> | ||
| 2 | <html> | ||
| 3 | <head> | ||
| 4 | <title>Ostsee - Verborgene Fracht - Login</title> | ||
| 5 | </head> | ||
| 6 | <style type="text/css"> | ||
| 7 | html,body | ||
| 8 | { | ||
| 9 | width:100%; | ||
| 10 | height:100%; | ||
| 11 | margin:0px; | ||
| 12 | padding:0px; | ||
| 13 | overflow:hidden; | ||
| 14 | } | ||
| 15 | |||
| 16 | body | ||
| 17 | { | ||
| 18 | position:absolute; | ||
| 19 | background:#474747; | ||
| 20 | vertical-align:middle; | ||
| 21 | } | ||
| 22 | |||
| 23 | form.login | ||
| 24 | { | ||
| 25 | position:relative; | ||
| 26 | top:50%; | ||
| 27 | display:block; | ||
| 28 | margin:auto auto; | ||
| 29 | width:12em; | ||
| 30 | text-align:right; | ||
| 31 | font-family:Arial, Helvetica Neue, Helvetica, sans-serif; | ||
| 32 | font-weight:bold; | ||
| 33 | transform: translateY(-50%); | ||
| 34 | } | ||
| 35 | |||
| 36 | form.login label | ||
| 37 | { | ||
| 38 | color:#fff; | ||
| 39 | text-align:center; | ||
| 40 | font-size:x-small; | ||
| 41 | text-transform:uppercase; | ||
| 42 | display:block; | ||
| 43 | font-weight:normal; | ||
| 44 | line-height:1.75em; | ||
| 45 | } | ||
| 46 | |||
| 47 | form.login :active, | ||
| 48 | form.login :focus | ||
| 49 | { | ||
| 50 | outline:0px; | ||
| 51 | } | ||
| 52 | |||
| 53 | form.login input | ||
| 54 | { | ||
| 55 | border:4px solid #fff; | ||
| 56 | border-radius:6px; | ||
| 57 | background:#fff; | ||
| 58 | width:100%; | ||
| 59 | margin:0px; | ||
| 60 | font-size:inherit; | ||
| 61 | text-align:center; | ||
| 62 | } | ||
| 63 | |||
| 64 | form.login button | ||
| 65 | { | ||
| 66 | clear:both; | ||
| 67 | display:block; | ||
| 68 | float:right; | ||
| 69 | background:#fff; | ||
| 70 | border:0px; | ||
| 71 | position:relative; | ||
| 72 | top:-1em; | ||
| 73 | margin-top:-5px; | ||
| 74 | font-size:inherit; | ||
| 75 | background:transparent; | ||
| 76 | color:#474747; | ||
| 77 | text-align:right; | ||
| 78 | } | ||
| 79 | </style> | ||
| 80 | <body onload="document.getElementById('password').focus()"> | ||
| 81 | <form action="/" class="login"> | ||
| 82 | <input type="hidden" name="username" id="username" value="login" /> | ||
| 83 | <label>Passwort <?php echo $_SERVER['PHP_AUTH_USER'].$_SERVER['REMOTE_USER'] ?><br/> | ||
| 84 | <input type="password" id="password" /></label> | ||
| 85 | <button type="submit" />></button> | ||
| 86 | <br style="clear:both" /> | ||
| 87 | </form> | ||
| 88 | </body> | ||
| 89 | </html> | ||
| 90 | |||
| 91 | <script type="text/javascript"> | ||
| 92 | //~ ajax-main-functions --------------------------------------------- ~ | ||
| 93 | function createHTTPObject() | ||
| 94 | { | ||
| 95 | var xmlhttp; | ||
| 96 | /*@cc_on | ||
| 97 | @if (@_jscript_version >= 5) try { | ||
| 98 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | ||
| 99 | } catch (e) { | ||
| 100 | try { | ||
| 101 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | ||
| 102 | } catch (E){ | ||
| 103 | xmlhttp = false; | ||
| 104 | } | ||
| 105 | } @else xmlhttp = false; @end @*/ | ||
| 106 | |||
| 107 | if (!xmlhttp && typeof XMLHttpRequest != 'undefined') | ||
| 108 | { | ||
| 109 | try { xmlhttp = new XMLHttpRequest(); } | ||
| 110 | catch (e) { xmlhttp = false; } | ||
| 111 | } | ||
| 112 | return xmlhttp; | ||
| 113 | } | ||
| 114 | |||
| 115 | function formSubmit(e) | ||
| 116 | { | ||
| 117 | var form = e.target; | ||
| 118 | var username = document.getElementById("username"); | ||
| 119 | var password = document.getElementById("password"); | ||
| 120 | var http = createHTTPObject(); | ||
| 121 | /* console.log("username: " + username.value + " password: " + password.value); */ | ||
| 122 | http.open("get", "index.html", false, username.value, password.value); | ||
| 123 | http.send(""); | ||
| 124 | if (http.status == 200) /* content got delivered, we are clear to pass (password was right) */ | ||
| 125 | { window.location = "http://ostsee.halbtotal.de/index.html"; return false; } | ||
| 126 | else if (http.status == 401) /* 401=authorization required when password was wrong */ | ||
| 127 | { password.value = ''; return false; } | ||
| 128 | else /* other errors lead to the default login page */ | ||
| 129 | { return false; } | ||
| 130 | } | ||
| 131 | |||
| 132 | for(var i in document.forms) | ||
| 133 | { document.forms[i].onsubmit=formSubmit; } | ||
| 134 | </script> | ||
| 135 | <!-- vim: set ts=2 sw=2 :smartindent --> | ||
| 136 | |||
