Skip to content

Commit 41781d0

Browse files
committed
Add login and register base code
0 parents  commit 41781d0

File tree

6 files changed

+613
-0
lines changed

6 files changed

+613
-0
lines changed

css/style.css

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
body {
2+
font: 20px "Lucida Grande", Tahoma, Verdana, sans-serif;
3+
color: #404040;
4+
}
5+
6+
input[type=text],
7+
input[type=password],
8+
input[type=email] {
9+
padding: 10px;
10+
width: 100%;
11+
}
12+
13+
#userNotes {
14+
font-size: 0.7em;
15+
text-align: left;
16+
padding: 10px;
17+
}
18+
19+
#actions {
20+
padding: 10px;
21+
}
22+
23+
#infoMesssage {
24+
padding: 10px;
25+
background-color: #BDE5F8;
26+
color: black;
27+
font-size: 0.8em;
28+
}
29+
30+
#successMessage {
31+
padding: 10px;
32+
background-color: green;
33+
color: white;
34+
}
35+
36+
#failedMessage {
37+
padding: 10px;
38+
background-color: red;
39+
color: white;
40+
font-size: 15px;
41+
}
42+
43+
#formBody {
44+
padding: 5px;
45+
}
46+
47+
#loginForm {
48+
49+
text-align: center;
50+
border: thin solid #000;
51+
width: 300px;
52+
margin: 7em auto 0 auto;
53+
}
54+
55+
#formHeader {
56+
border-bottom: thin solid gray;
57+
padding: 10px;
58+
background: #f3f3f3;
59+
}
60+
61+
#loginForm {
62+
63+
}
64+
65+
.customButton {
66+
padding: 5px;
67+
width: 100%;
68+
-moz-box-shadow: inset 0px 1px 0px 0px #bbdaf7;
69+
-webkit-box-shadow: inset 0px 1px 0px 0px #bbdaf7;
70+
box-shadow: inset 0px 1px 0px 0px #bbdaf7;
71+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #79bbff), color-stop(1, #378de5));
72+
background: -moz-linear-gradient(center top, #79bbff 5%, #378de5 100%);
73+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#378de5');
74+
background-color: #79bbff;
75+
-moz-border-radius: 6px;
76+
-webkit-border-radius: 6px;
77+
border-radius: 6px;
78+
border: 1px solid #84bbf3;
79+
display: inline-block;
80+
color: #ffffff;
81+
font-family: arial;
82+
font-size: 15px;
83+
font-weight: bold;
84+
text-decoration: none;
85+
text-shadow: 1px 1px 0px #528ecc;
86+
cursor: pointer;
87+
}
88+
89+
.customButton:hover {
90+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff));
91+
background: -moz-linear-gradient(center top, #378de5 5%, #79bbff 100%);
92+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#378de5', endColorstr='#79bbff');
93+
background-color: #378de5;
94+
}
95+
96+
.customButton:active {
97+
position: relative;
98+
top: 1px;
99+
}
100+
101+
/* This imageless css button was generated by CSSButtonGenerator.com */

libs/DbConnect.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
$host = "localhost";
3+
$db_name = "coan_secure";
4+
$username = "root";
5+
$password = "";
6+
7+
try {
8+
$con = new PDO("mysql:host={$host};dbname={$db_name}", $username, $password);
9+
} //to handle connection error
10+
catch (PDOException $exception) {
11+
echo "Connection error: " . $exception->getMessage();
12+
}
13+
?>

libs/PasswordHash.php

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
<?php
2+
#
3+
# Portable PHP password hashing framework.
4+
#
5+
# Version 0.3 / genuine.
6+
#
7+
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
8+
# the public domain. Revised in subsequent years, still public domain.
9+
#
10+
# There's absolutely no warranty.
11+
#
12+
# The homepage URL for this framework is:
13+
#
14+
# http://www.openwall.com/phpass/
15+
#
16+
# Please be sure to update the Version line if you edit this file in any way.
17+
# It is suggested that you leave the main version number intact, but indicate
18+
# your project name (after the slash) and add your own revision information.
19+
#
20+
# Please do not change the "private" password hashing method implemented in
21+
# here, thereby making your hashes incompatible. However, if you must, please
22+
# change the hash type identifier (the "$P$") to something different.
23+
#
24+
# Obviously, since this code is in the public domain, the above are not
25+
# requirements (there can be none), but merely suggestions.
26+
#
27+
class PasswordHash
28+
{
29+
var $itoa64;
30+
var $iteration_count_log2;
31+
var $portable_hashes;
32+
var $random_state;
33+
34+
function PasswordHash($iteration_count_log2, $portable_hashes)
35+
{
36+
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
37+
38+
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
39+
$iteration_count_log2 = 8;
40+
}
41+
$this->iteration_count_log2 = $iteration_count_log2;
42+
43+
$this->portable_hashes = $portable_hashes;
44+
45+
$this->random_state = microtime();
46+
if (function_exists('getmypid')) {
47+
$this->random_state .= getmypid();
48+
}
49+
}
50+
51+
function get_random_bytes($count)
52+
{
53+
$output = '';
54+
if (is_readable('/dev/urandom')
55+
&& ($fh = @fopen('/dev/urandom', 'rb'))
56+
) {
57+
$output = fread($fh, $count);
58+
fclose($fh);
59+
}
60+
61+
if (strlen($output) < $count) {
62+
$output = '';
63+
for ($i = 0; $i < $count; $i += 16) {
64+
$this->random_state = md5(microtime() . $this->random_state);
65+
$output .= pack('H*', md5($this->random_state));
66+
}
67+
$output = substr($output, 0, $count);
68+
}
69+
70+
return $output;
71+
}
72+
73+
function encode64($input, $count)
74+
{
75+
$output = '';
76+
$i = 0;
77+
do {
78+
$value = ord($input[$i++]);
79+
$output .= $this->itoa64[$value & 0x3f];
80+
if ($i < $count) {
81+
$value |= ord($input[$i]) << 8;
82+
}
83+
$output .= $this->itoa64[($value >> 6) & 0x3f];
84+
if ($i++ >= $count) {
85+
break;
86+
}
87+
if ($i < $count) {
88+
$value |= ord($input[$i]) << 16;
89+
}
90+
$output .= $this->itoa64[($value >> 12) & 0x3f];
91+
if ($i++ >= $count) {
92+
break;
93+
}
94+
$output .= $this->itoa64[($value >> 18) & 0x3f];
95+
} while ($i < $count);
96+
97+
return $output;
98+
}
99+
100+
function gensalt_private($input)
101+
{
102+
$output = '$P$';
103+
$output .= $this->itoa64[min(
104+
$this->iteration_count_log2 + ((PHP_VERSION >= '5') ? 5 : 3),
105+
30
106+
)];
107+
$output .= $this->encode64($input, 6);
108+
109+
return $output;
110+
}
111+
112+
function crypt_private($password, $setting)
113+
{
114+
$output = '*0';
115+
if (substr($setting, 0, 2) == $output) {
116+
$output = '*1';
117+
}
118+
119+
$id = substr($setting, 0, 3);
120+
# We use "$P$", phpBB3 uses "$H$" for the same thing
121+
if ($id != '$P$' && $id != '$H$') {
122+
return $output;
123+
}
124+
125+
$count_log2 = strpos($this->itoa64, $setting[3]);
126+
if ($count_log2 < 7 || $count_log2 > 30) {
127+
return $output;
128+
}
129+
130+
$count = 1 << $count_log2;
131+
132+
$salt = substr($setting, 4, 8);
133+
if (strlen($salt) != 8) {
134+
return $output;
135+
}
136+
137+
# We're kind of forced to use MD5 here since it's the only
138+
# cryptographic primitive available in all versions of PHP
139+
# currently in use. To implement our own low-level crypto
140+
# in PHP would result in much worse performance and
141+
# consequently in lower iteration counts and hashes that are
142+
# quicker to crack (by non-PHP code).
143+
if (PHP_VERSION >= '5') {
144+
$hash = md5($salt . $password, true);
145+
do {
146+
$hash = md5($hash . $password, true);
147+
} while (--$count);
148+
} else {
149+
$hash = pack('H*', md5($salt . $password));
150+
do {
151+
$hash = pack('H*', md5($hash . $password));
152+
} while (--$count);
153+
}
154+
155+
$output = substr($setting, 0, 12);
156+
$output .= $this->encode64($hash, 16);
157+
158+
return $output;
159+
}
160+
161+
function gensalt_extended($input)
162+
{
163+
$count_log2 = min($this->iteration_count_log2 + 8, 24);
164+
# This should be odd to not reveal weak DES keys, and the
165+
# maximum valid value is (2**24 - 1) which is odd anyway.
166+
$count = (1 << $count_log2) - 1;
167+
168+
$output = '_';
169+
$output .= $this->itoa64[$count & 0x3f];
170+
$output .= $this->itoa64[($count >> 6) & 0x3f];
171+
$output .= $this->itoa64[($count >> 12) & 0x3f];
172+
$output .= $this->itoa64[($count >> 18) & 0x3f];
173+
174+
$output .= $this->encode64($input, 3);
175+
176+
return $output;
177+
}
178+
179+
function gensalt_blowfish($input)
180+
{
181+
# This one needs to use a different order of characters and a
182+
# different encoding scheme from the one in encode64() above.
183+
# We care because the last character in our encoded string will
184+
# only represent 2 bits. While two known implementations of
185+
# bcrypt will happily accept and correct a salt string which
186+
# has the 4 unused bits set to non-zero, we do not want to take
187+
# chances and we also do not want to waste an additional byte
188+
# of entropy.
189+
$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
190+
191+
$output = '$2a$';
192+
$output .= chr(ord('0') + $this->iteration_count_log2 / 10);
193+
$output .= chr(ord('0') + $this->iteration_count_log2 % 10);
194+
$output .= '$';
195+
196+
$i = 0;
197+
do {
198+
$c1 = ord($input[$i++]);
199+
$output .= $itoa64[$c1 >> 2];
200+
$c1 = ($c1 & 0x03) << 4;
201+
if ($i >= 16) {
202+
$output .= $itoa64[$c1];
203+
break;
204+
}
205+
206+
$c2 = ord($input[$i++]);
207+
$c1 |= $c2 >> 4;
208+
$output .= $itoa64[$c1];
209+
$c1 = ($c2 & 0x0f) << 2;
210+
211+
$c2 = ord($input[$i++]);
212+
$c1 |= $c2 >> 6;
213+
$output .= $itoa64[$c1];
214+
$output .= $itoa64[$c2 & 0x3f];
215+
} while (1);
216+
217+
return $output;
218+
}
219+
220+
function HashPassword($password)
221+
{
222+
$random = '';
223+
224+
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
225+
$random = $this->get_random_bytes(16);
226+
$hash = crypt($password, $this->gensalt_blowfish($random));
227+
if (strlen($hash) == 60) {
228+
return $hash;
229+
}
230+
}
231+
232+
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
233+
if (strlen($random) < 3) {
234+
$random = $this->get_random_bytes(3);
235+
}
236+
$hash = crypt($password, $this->gensalt_extended($random));
237+
if (strlen($hash) == 20) {
238+
return $hash;
239+
}
240+
}
241+
242+
if (strlen($random) < 6) {
243+
$random = $this->get_random_bytes(6);
244+
}
245+
$hash = $this->crypt_private(
246+
$password,
247+
$this->gensalt_private($random)
248+
);
249+
if (strlen($hash) == 34) {
250+
return $hash;
251+
}
252+
253+
# Returning '*' on error is safe here, but would _not_ be safe
254+
# in a crypt(3)-like function used _both_ for generating new
255+
# hashes and for validating passwords against existing hashes.
256+
return '*';
257+
}
258+
259+
function CheckPassword($password, $stored_hash)
260+
{
261+
$hash = $this->crypt_private($password, $stored_hash);
262+
if ($hash[0] == '*') {
263+
$hash = crypt($password, $stored_hash);
264+
}
265+
266+
return $hash == $stored_hash;
267+
}
268+
}
269+
270+
?>

0 commit comments

Comments
 (0)