Commit 5fb44d05 authored by Xavier Guimard's avatar Xavier Guimard

Captcha in progress (#595)

parent 82acb302
......@@ -35,7 +35,7 @@ has ott => (
}
);
# Returns secret + a HTML <img> tag with embedded image
# Returns secret + a HTML image src content
sub getCaptcha {
my ($self) = @_;
my $image = GD::SecurityImage->new(
......@@ -49,8 +49,7 @@ sub getCaptcha {
$image->random;
$image->create( 'normal', 'default', $self->fgColor, $self->bgColor );
my ( $imageData, $mimeType, $rdm ) = $image->out( force => 'png' );
my $img = '<img src="data:image/png;base64,'
. encode_base64( $imageData, '' ) . '">';
my $img = 'data:image/png;base64,' . encode_base64( $imageData, '' );
my $token = $self->ott->createToken( { captcha => $rdm } );
return ( $token, $img );
}
......@@ -63,7 +62,8 @@ sub validateCaptcha {
return 0;
}
unless ( $s->{captcha} == $value ) {
$self->lmLog( 'Bad captcha response', 'notice' ) return 0;
$self->lmLog( 'Bad captcha response', 'notice' );
return 0;
}
$self->lmLog( 'Good captcha response', 'debug' );
return 1;
......
......@@ -182,12 +182,16 @@ sub display {
);
# Display captcha if it's enabled
if ( $self->{captcha_login_enabled} ) {
if ( $req->captcha ) {
%templateParams = (
%templateParams,
CAPTCHA_IMG => $req->{captcha_img},
CAPTCHA_CODE => $req->{captcha_code},
CAPTCHA_SIZE => $req->{captcha_size}
CAPTCHA_SRC => $req->captcha,
);
}
if ( $req->token ) {
%templateParams = (
%templateParams,
TOKEN => $req->token,
);
}
......
......@@ -25,15 +25,17 @@
<input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">" class="form-control" trplaceholder="mail" required />
</div>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<div class="form-group">
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" class="img-thumbnail" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" class="img-thumbnail" />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-eye-open"></i> </span>
<input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
<input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
</div>
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" />
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<button type="submit" class="btn btn-success" >
......
......@@ -33,15 +33,17 @@
<input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">" class="form-control" trplaceholder="mail" required />
</div>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<div class="form-group">
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" class="img-thumbnail" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" class="img-thumbnail" />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-eye-open"></i> </span>
<input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
<input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
</div>
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" />
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<button type="submit" class="btn btn-success" >
......
......@@ -9,15 +9,17 @@
<input name="password" type="password" class="form-control" trplaceholder="password" required />
</div>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<div class="form-group">
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" class="img-thumbnail" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" class="img-thumbnail" />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-eye-open"></i> </span>
<input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
<input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" class="form-control" placeholder="Captcha" required />
</div>
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" />
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<TMPL_INCLUDE NAME="checklogins.tpl">
......
......@@ -23,15 +23,17 @@
<th><span trspan="mail">Mail</span></th>
<td><input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">" /></td>
</tr>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<tr><td></td><td>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" />
</td></tr>
<tr><th><span trspan="captcha">Captcha</span></th>
<td><input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" /></td>
<td><input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" /></td>
</tr>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<tr>
<td colspan="2">
<div class="buttons">
......
......@@ -31,15 +31,17 @@
<th><span trspan="mail">Mail</span></th>
<td><input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">" /></td>
</tr>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<tr><td></td><td>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" />
</td></tr>
<tr><th><span trspan="captcha">Captcha</span></th>
<td><input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" /></td>
<td><input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" /></td>
</tr>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<tr>
<td colspan="2">
<div class="buttons">
......
......@@ -7,16 +7,18 @@
<input name="password" type="password" tabindex="2" /><br/>
</p>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<p>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" />
</p>
<p>
<span class="text-label"><span trspan="captcha">Captcha</span></span><br />
<input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" tabindex="3" /><br />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" />
<input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" tabindex="3" /><br />
</p>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<TMPL_IF NAME="CHECK_LOGINS">
<p>
......
......@@ -25,15 +25,17 @@
<td><input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">"/></td>
</tr>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<tr><td></td><td>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" />
</td></tr>
<tr><th><span trspan="captcha">Captcha</span></th>
<td><input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" /></td>
<td><input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" /></td>
</tr>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<tr><td colspan="2">
<div class="buttons">
......
......@@ -35,15 +35,17 @@
<td><input name="mail" type="text" value="<TMPL_VAR NAME="MAIL">"/></td>
</tr>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME=CAPTCHA_SRC>
<tr><td></td><td>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" />
</td></tr>
<tr><th><span trspan="captcha">Captcha</span></th>
<td><input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" /></td>
<td><input type="text" name="captcha" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" /></td>
</tr>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<tr><td colspan="2">
<div class="buttons">
......
......@@ -8,15 +8,17 @@
<td><input name="password" type="password" tabindex="2" /></td>
</tr>
<TMPL_IF NAME=CAPTCHA_IMG>
<TMPL_IF NAME="CAPTCHA_SRC">
<tr><td></td><td>
<img src="<TMPL_VAR NAME=CAPTCHA_IMG>" />
<img src="<TMPL_VAR NAME="CAPTCHA_SRC">" />
</td></tr>
<tr><th><span trspan="captcha">Captcha</span></th>
<td><input type="text" name="captcha_user_code" size="<TMPL_VAR NAME=CAPTCHA_SIZE>" tabindex="3" />
<input type="hidden" name="captcha_code" value="<TMPL_VAR NAME=CAPTCHA_CODE>" /></td>
<td><input type="text" name="captcha" size="<TMPL_VAR NAME="CAPTCHA_SIZE">" tabindex="3" /></td>
</tr>
</TMPL_IF>
<TMPL_IF NAME="TOKEN">
<input type!"hidden" name="token" value="<TMPL_IF NAME="TOKEN">" />
</TMPL_IF>
<TMPL_IF NAME="CHECK_LOGINS">
<tr><td colspan="2"><div class="buttons">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment