Jump to content

PHP captcha without graphics ?


VanDerSaAr

Recommended Posts

My guess is that both of you are using Windows, and thus has the same font that the OP relies upon for the formatting.

Yes, I am on Windows 7.

 

What console font in your operation system? I can add this font name in my forum right now.

 

Like Jesi said, add "monospace" to the end of the font-family list. That way if somebody doesn't have any of the fonts, it will use the default monospace font specified on their system.

 

EDIT: But, you should host a font and use that to make sure it renders (close to) the same for everyone.

 

Also keep in mind that people can zoom text, which might break your captcha.

Link to comment
Share on other sites

VanDerSaAr: I'd think it would be rather obvious from my pictures, but no: I don't have those fonts. The closest I get, in terms of name, is "Courier 10 Pitch".

Having the correct fonts (or not) isn't really the core issue, but rather a symptom of the real problem. Namely that you're relying on client-side conditions for your validation. Conditions which you have no control over.

 

Not to mention those who are blind or have reduced eye-sight, as no screen-reader would be able to make heads or tails out of this. In fact, I pity anyone who'd try to run that through a screen-reader.

Link to comment
Share on other sites

Not to mention those who are blind or have reduced eye-sight, as no screen-reader would be able to make heads or tails out of this. In fact, I pity anyone who'd try to run that through a screen-reader.

 

If it worked on a screen reader, it would probably defeat the whole purpose.

Link to comment
Share on other sites

ConsoleCaptcha 1.1

 

Changes: Added Monospace to font family, corrected several comments.

 

<?php

/*=============================================================================================

ConsoleCaptcha (c)
Version: 1.1 (2012-08-29)

Author: VanDerSaAr

ConsoleCaptcha generates text based images with symbols, which enough easily can be read by humans, but difficulty can be read by OCR systems or other robots. It does not require any graphic library (GD, etc), any database of questions, etc. It does not use much resources and more faster. It can be used with telnet, ssh, etc.

See example: http://cryptbb.site40.net/reg.php?v=1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

License: MIT

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-----------------------------------------------------------------------------------------------

How to use ConsoleCaptcha v1.1:

<code>
<?php
include("console-captcha-v1.php");
echo ConsoleCaptchaV1(
  "EFHLN", # random captcha text = string of 1..30 symbols from EFHLNTXZ + space
  4,    # defined font size              = 1..24 pixels
  21,   # defined canvas height          = 13..100 symbols
  120,  # minimal canvas width           = 0..600 symbols
  
  12,   # minimal strike line height     = 12..min_canvas_width
  50,   # minimal strike line width      = 50..100 symbols
  30,   # maximal add strike line width  = 0..50 symbols
  15,   # maximal inverval between strike lines = 0..25 symbols
  
  10,   # minimal letter size            = 10..canvas_height-3
  100,  # maximal letter size            = min_letter_size..canvas_height-3
  0,    # minimal interval between letters = 0..100 symbols
  4,    # maximal interval between letters = min_interval_letter..100
  
  10);  # maximal deviation of letter from vertical line = 0..30 degrees
?>
</code>

To check captcha you can use hashes, sessions, etc.

*///===========================================================================================

function ConsoleCaptchaV1(
  $CaptchaText, // = "EFHLN" # random captcha text = 1..30 symbols from EFHLNTXZ + space
  $FontSize,          // = 4    # defined font size              = 1..24
  $CanvasHeight,      // = 21   # defined canvas height          = 13..100
  $MinCanvasWidth,    // = 120  # minimal canvas width           = 0..600
  $MinStrikeHeight,   // = 12   # minimal strike line height     = 12..$MinCanvasWidth
  $MinStrikeLength,   // = 50   # minimal strike line width      = 50..100
  $AddStrikeLength,   // = 30   # maximal add strike line width  = 30..50
  $MaxStrikeInterval, // = 15   # maximal inverval between strike lines = 15..25
  $MinLetterSize,     // = 10   # minimal symbol size            = 10..$CanvasHeight-3
  $MaxLetterSize,     // = 100  # maximal symbol size            = 100..$CanvasHeight-3
  $MinLetterInterval, // = 0    # minimal interval between minimal symbol size = 0..100
  $MaxLetterInterval, // = 4    # maximal interval between minimal symbol size = 4..100
  $MaxLetterAngle     // = 10   # maximal deviation of symbol from vertical line = 0..30
  ) {

#==============================================================================================  

function FuncAngleX($FuncX, $FuncAngle, $FuncSize) { # func (origin x, pos angle, pos length)

  if (($FuncAngle >= (M_PI / 2)) and ($FuncAngle < (3 * M_PI / 2))) { # if angle = PI/2 .. 3*PI/2
  
    $FuncX = $FuncX - round($FuncSize * cos($FuncAngle)); # set position x

  } else { # if (($FuncAngle >= (M_PI / 2)) and ($FuncAngle < (3 * M_PI / 2))) # if angle = 0..PI/2 + 3*PI/2..2*PI

    if ($FuncAngle < (M_PI / 2)) { # if angle = 0 .. PI/2
      $FuncX = $FuncX + round($FuncSize * cos(M_PI - $FuncAngle)); # set position x
    } else { # if ($FuncAngle < (M_PI / 2)) # if angle = 3*PI/2 .. 2*PI
      $FuncX = $FuncX + round($FuncSize * cos($FuncAngle - M_PI)); # set position x
} # if ($FuncAngle < (M_PI / 2)) else

  } # if (($FuncAngle >= (M_PI / 2)) and ($FuncAngle < (3 * M_PI / 2))) else
  
  return $FuncX; # return position x    
  
} # function FuncAngleX ($FuncX, $FuncAngle, $FuncSize)

#----------------------------------------------------------------------------------------------

function FuncPointPos($FuncOriginX, $FuncOriginY, $FuncRatio, $FuncSize1, $FuncAngle1,
$FuncSize2, $FuncAngle2) { # func (origin x, y; factor y; positions length, angle of degrees)

  $FuncA = ($FuncAngle1 / 180) * M_PI; # set position1 angle
  
  if ($FuncA > (2 * M_PI)) { # if angle more 2*PI
    $FuncA = $FuncA - (2 * M_PI); # decrease angle
  } # if ($FuncA > (2 * M_PI))
  if ($FuncA < 0) { # if angle less 0
    $FuncA = $FuncA + (2 * M_PI); # increase angle
  } # if ($FuncA < 0)
  
  $FuncX1 = FuncAngleX($FuncOriginX, $FuncA, $FuncSize1); # set position1 x
  $FuncY1 = $FuncOriginY + round(($FuncSize1 * sin($FuncA)) / $FuncRatio); # set position1 y

  $FuncA = ($FuncAngle2 / 180) * M_PI; # set position2 angle
  
  if ($FuncA > (2 * M_PI)) { # if angle more 2*PI
    $FuncA = $FuncA - (2 * M_PI); # decrease angle
  } # if ($FuncA > (2 * M_PI))
  if ($FuncA < 0) { # if angle less 0
    $FuncA = $FuncA + (2 * M_PI); # increase angle
  } # if ($FuncA < 0)
  
  $FuncX2 = FuncAngleX($FuncOriginX, $FuncA, $FuncSize2); # set position2 x
  $FuncY2 = $FuncOriginY + round(($FuncSize2 * sin($FuncA)) / $FuncRatio); # set position2 y
  
  return array ($FuncX1, $FuncY1, $FuncX2, $FuncY2); # return positions x1, y1, x2, y2
  
} # function FuncPointPos()

#==============================================================================================  

  $NeedDebug = false; # if need to print tech info
  
  #$FontSize = 4; // 4 # get font size // debug
  if ($FontSize < 1) {$FontSize = 1;} # if value less min value then set min value
  if ($FontSize > 24) {$FontSize = 24;} # if value more max value then set max value
  
  #$CanvasHeight = 21; // 21 # get canvas height // debug
  if ($CanvasHeight < 13) {$CanvasHeight = 13;} # if value less min value then set min value
  if ($CanvasHeight > 100) {$CanvasHeight = 100;} # if value more max value then set max value

  #$MinCanvasWidth = 120; // 120 # get minimal canvas width // debug
  if ($MinCanvasWidth < 0) {$MinCanvasWidth = 0;} # if value less min value then set min value
  if ($MinCanvasWidth > 600) {$MinCanvasWidth = 600;} # if value more max value then set max value

  #$MinStrikeHeight = 12; // 12 # get minimal strike line height // debug
  if ($MinStrikeHeight < 12) {$MinStrikeHeight = 12;} # if value less min value then set min value
  if ($MinStrikeHeight > $CanvasHeight) {$MinStrikeHeight = $CanvasHeight;} # if value more max value then set max value
  
  #$MinStrikeLength = 50; // 50 # get minimal strike line length // debug
  if ($MinStrikeLength < 50) {$MinStrikeLength = 50;} # if value less min value then set min value
  if ($MinStrikeLength > 100) {$MinStrikeLength = 100;} # if value more max value then set max value

  #$AddStrikeLength = 30; // 30 # get maximal add strike line height // debug
  if ($AddStrikeLength < 0) {$AddStrikeLength = 0;} # if value less min value then set min value
  if ($AddStrikeLength > 50) {$AddStrikeLength = 50;} # if value more max value then set max value

  #$MaxStrikeInterval = 15; // 15 # get maximal inverval between strike lines // debug
  if ($MaxStrikeInterval < 0) {$MaxStrikeInterval = 0;} # if value less min value then set min value
  if ($MaxStrikeInterval > 25) {$MaxStrikeInterval = 25;} # if value more max value then set max value
  
  #$MinLetterSize = 10; // 10 # get minimal symbol size // debug
  if ($MinLetterSize < 10) {$MinLetterSize = 10;} # if value less min value then set min value
  if ($MinLetterSize > $CanvasHeight - 3) {$MinLetterSize = $CanvasHeight - 3;} # if value more max value then set max value
  
  #$MaxLetterSize = 100; // 100 # get maximal symbol size // debug
  if ($MaxLetterSize < $MinLetterSize) {$MaxLetterSize = $MinLetterSize;} # if value less min value then set min value
  if ($MaxLetterSize > $CanvasHeight - 3) {$MaxLetterSize = $CanvasHeight - 3;} # if value more max value then set max value

  #$MinLetterInterval = 0; // 0 # get minimal interval between minimal symbol size // debug
  if ($MinLetterInterval < 0) {$MinLetterInterval = 0;} # if value less min value then set min value
  if ($MinLetterInterval > 100) {$MinLetterInterval = 100;} # if value more max value then set max value
  
  #$MaxLetterInterval = 4; // 4 # get maximal interval between minimal symbol size // debug
  if ($MaxLetterInterval < $MinLetterInterval) {$MaxLetterInterval = $MinLetterInterval;} # if value less min value then set min value
  if ($MaxLetterInterval > 100) {$MaxLetterInterval = 100;} # if value more max value then set max value

  #$MaxLetterAngle = 10; // 10 # get maximal deviation of symbol from vertical line // debug
  if ($MaxLetterAngle < 0) {$MaxLetterAngle = 0;} # if value less min value then set min value
  if ($MaxLetterAngle > 30) {$MaxLetterAngle = 30;} # if value more max value then set max value

#----------------------------------------------------------------------------------------------  
  
  if ($FontSize < 3) { # if letters too small
    $CanvasBackChars = " "; # set canvas background chars
  } else { # if ($FontSize < 3)
    $CanvasBackChars = ".,' "; # set canvas background chars  
  } # if ($FontSize < 3) else

  $CanvasFrontChars = "#@&"; # set canvas front chars  
  $DrawChar = "*"; # set temp draw char
  $SpaceChar = " "; # set temp space char
  $Ratio = "1.73"; # set ratio between width and height of symbols

  for ($For1 = 1; $For1 <= $CanvasHeight; $For1++) { # cycle lines of canvas
  
    if ($NeedDebug === true) { # if need to debug
      $Line[$For1] = sprintf('%1$02d', $For1); # set line number
} else { # if ($NeedDebug === true) # if not need to debug
  $Line[$For1] = $SpaceChar; # set space
} # if ($NeedDebug === true) else

  } # for ($For1 = 1; $For1 <= $CanvasHeight; $For1++)

  $DrawCount = 0; # clear draw lines count
  $OriginX = 2; # set start symbol position

  $PointX1 = array(); # assign array of x1 point of draw line
  $PointY1 = array(); # assign array of y1 point of draw line
  $PointX2 = array(); # assign array of x2 point of draw line
  $PointY2 = array(); # assign array of y2 point of draw line
  
  for ($For1 = (strlen($CaptchaText) - 1); $For1 >= 0; $For1--) { # cycle symbols of captcha text
  
    if (strpos('EFHLNTXZ ', $CaptchaText[$For1]) === false) { # if captcha symbol is unknown and not space
  $CaptchaText = substr_replace($CaptchaText, "", $For1, 1); # delete symbol
} # if (strpos('EFHLNTXZ ', $CaptchaText[$For1]) === false)

  } # for ($For1 = (strlen($CaptchaText) - 1); $For1 >= 0; $For1--)
  
  if (strlen($CaptchaText) > 30) { # if length of captcha text more value
    $CaptchaText = substr($CaptchaText, 0, 30); # cut captcha text from right side
  } # if (strlen($CaptchaText) > 30)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

for ($For1 = 0; $For1 < strlen($CaptchaText); $For1++) { # cycle symbols of captcha

  $OriginX = $OriginX + rand($MinLetterInterval, $MaxLetterInterval); # increase origin x plus random interval

  $MainSize = rand($MinLetterSize, $MaxLetterSize); # randomize letter size
  #$MainSize = 7; # debug

  $DeltaA = rand(0, $MaxLetterAngle * 2) - $MaxLetterAngle; # randomize angle delta
  #$DeltaA = 0; # debug

  $OriginY = rand(ceil($MainSize / 2) + 2, $CanvasHeight - ceil($MainSize / 2) - 1); # randomize origin y = 08..14
  
  $OriginX = $OriginX + ceil($MainSize / 2) + 1; # increase origin x plus half letter size
  
#----------------------------------------------------------------------------------------------  

if (strpos('EFHLN', $CaptchaText[$For1]) !== false) { # left column begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 300 + $DeltaA, $MainSize, 60 + $DeltaA);
} # left column end

if (strpos('EFTZ', $CaptchaText[$For1]) !== false) { # top row begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 300 + $DeltaA, $MainSize, 240 + $DeltaA);
} # top row end

if (strpos('EFH', $CaptchaText[$For1]) !== false) { # middle row begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize / 2.1, 0 + $DeltaA, $MainSize / 2.1, 180 + $DeltaA);
} # middle row end	
  
if (strpos('ELZ', $CaptchaText[$For1]) !== false) { # bottom row begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 60 + $DeltaA, $MainSize, 120 + $DeltaA);
} # # bottom row end
  
if (strpos('HN', $CaptchaText[$For1]) !== false) { # right column begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 240 + $DeltaA, $MainSize, 120 + $DeltaA);
} # right column end

if (strpos('T', $CaptchaText[$For1]) !== false) { # middle column begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize / 1.2, 270 + $DeltaA, $MainSize / 1.2, 90 + $DeltaA);
} # middle column end

if (strpos('NX', $CaptchaText[$For1]) !== false) { # diagonal \ begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 300 + $DeltaA, $MainSize, 120 + $DeltaA);
} # diagonal \ end

if (strpos('XZ', $CaptchaText[$For1]) !== false) { # diagonal / begin
  $DrawCount = $DrawCount + 1; # increase line count
  list ($PointX1[$DrawCount], $PointY1[$DrawCount], $PointX2[$DrawCount], $PointY2[$DrawCount]) =
  FuncPointPos($OriginX, $OriginY, $Ratio, $MainSize, 240 + $DeltaA, $MainSize, 60 + $DeltaA);
} # diagonal / begin

#----------------------------------------------------------------------------------------------  
  
  $OriginX = $OriginX + ceil($MainSize / 2) + 1; # increase origin x plus half letter size
  
} # for ($For1 = 0; $For1 < strlen($CaptchaText); $For1++)

#==============================================================================================

$OriginX = $OriginX + 2; # increase origin x
$MarginX = 0; # clear margin x

if ($OriginX < $MinCanvasWidth) { # if origin x less minimal canvas width
  $MarginX = rand(0, $MinCanvasWidth - $OriginX); # randomize margin x
  $OriginX = $MinCanvasWidth; # set margin x
} # if ($OriginX < $MinCanvasWidth)

for ($For1 = 1; $For1 <= $DrawCount; $For1++) { # cycle draw lines
  $PointX1[$For1] = $PointX1[$For1] + $MarginX; # shift position x1 of draw line point
  $PointX2[$For1] = $PointX2[$For1] + $MarginX; # shift position x2 of draw line point
} # for ($For1 = 1; $For1 <= $DrawCount; $For1++)

#----------------------------------------------------------------------------------------------
  
$DotX1 = 1; # clear dot x1

while ($DotX1 < $OriginX) { # while dot x1 less right side of canvas

  $DotX2 = $DotX1 + $MinStrikeLength + rand(0, $AddStrikeLength); # set dot x2
  
  if ($DotX2 >= ($OriginX - $MinStrikeLength)) { # if dot x2 near right side
    $DotX2 = $OriginX; # set origin x to dot x2
  } # if ($DotX2 >= ($OriginX - $MinStrikeLength))

  if ($DotX1 != 1) { # if it is not left side
  
    if (($DotX2 - $DotX1) > ($MinStrikeLength + $AddStrikeLength)) { # if x1 x2 delta more strike line length
      $DotX1 = $DotX2 - ($MinStrikeLength + $AddStrikeLength); # set dot x1
    } # if (($DotX2 - $DotX1) > ($MinStrikeLength + $AddStrikeLength))

  } # if ($DotX1 != 1)

#----------------------------------------------------------------------------------------------
  
  if (($MinStrikeHeight * 2) > $CanvasHeight) { # if canvas height less doubled minimal strike line height
  
    if (rand(0, 1) == 1) { # if 50%/50%
  $DotY1 = rand(1, $CanvasHeight - $MinStrikeHeight + 1); # randomize left position of strike line
} else { # if (rand(0, 1) == 1)
  $DotY1 = rand($MinStrikeHeight, $CanvasHeight); # randomize left position of strike line
} # if (rand(0, 1) == 1) else

  } else { # if (($MinStrikeHeight * 2) > $CanvasHeight)
  
    $DotY1 = rand(1, $CanvasHeight); # randomize left position of strike line

  } # if (($MinStrikeHeight * 2) > $CanvasHeight) else

  if (($DotY1 - $MinStrikeHeight + 1) < 1) { # if left position of strike line near top of canvas  
$DotY2 = rand($DotY1 + $MinStrikeHeight - 1, $CanvasHeight); # randomize right position of strike line 	
  } else { # if (($DotY1 - $MinStrikeHeight + 1) < 1)  
  
    if (($DotY1 + $MinStrikeHeight - 1) > $CanvasHeight) { # if left position of strike line near bottom of canvas	
  $DotY2 = rand(1, $DotY1 - $MinStrikeHeight + 1); # randomize right position of strike line 	  
} else { # if (($DotY1 + $MinStrikeHeight - 1) > $CanvasHeight)

      if (rand(0, 1) == 1) { # if 50%/50%
    $DotY2 = rand($DotY1 + $MinStrikeHeight - 1, $CanvasHeight); # randomize right position of strike line 
  } else { # if (rand(0, 1) == 1)
    $DotY2 = rand(1, $DotY1 - $MinStrikeHeight + 1); # randomize right position of strike line 
  } # if (rand(0, 1) == 1) else
  
} # if (($DotY1 + $MinStrikeHeight - 1) > $CanvasHeight) else			
  } # if (($DotY1 - $MinStrikeHeight + 1) < 1) else

#----------------------------------------------------------------------------------------------
  
  $DrawCount = $DrawCount + 1; # increase draw line count
  $PointX1[$DrawCount] = $DotX1; # set point x1
  $PointY1[$DrawCount] = $DotY1; # set point y1
  $PointX2[$DrawCount] = $DotX2; # set point x2
  $PointY2[$DrawCount] = $DotY2; # set point y2
  
  $DotX1 = $DotX2 + rand(0, $MaxStrikeInterval); # increase dot x1
  
} # while ($DotX1 < $OriginX)

#==============================================================================================

// draw lines on canvas

for ($For1 = 1; $For1 <= $DrawCount; $For1++) { # cycle draw lines
  $DotX1 = $PointX1[$For1]; # get dot x1
  $DotY1 = $PointY1[$For1]; # get dot y1
  $DotX2 = $PointX2[$For1]; # get dot x2
  $DotY2 = $PointY2[$For1]; # get dot y2
  
  if ($NeedDebug == true) { # if need to debug
    echo 'DotX1=' . $DotX1 . ', DotY1=' . $DotY1 . ';'
. ' DotX2=' . $DotX2 . ', DotY2=' . $DotY2 . ': '; # print coordinates
  } # if ($NeedDebug == true)

  if ($DotX1 < $DotX2) { # if need to debug
    $FromX = $DotX1; # set left position x
  } else { # if ($DotX1 < $DotX2)
    $FromX = $DotX2; # set right position x
  } # if ($DotX1 < $DotX2) else
  if ($DotY1 < $DotY2) { # if need to debug
    $FromY = $DotY1; # set top position y
  } else { # if ($DotY1 < $DotY2)
    $FromY = $DotY2; # set bottom position y
  } # if ($DotY1 < $DotY2) else
  
  if ($NeedDebug == true) { # if need to debug
    echo 'FromX=' . $FromX . ', FromY=' . $FromY . '; '; # print coordinates
  } # if ($NeedDebug == true)
  
  $DeltaX = abs($DotX1 - $DotX2); # set delta x
  $DeltaY = abs($DotY1 - $DotY2); # set delta y

  if ($NeedDebug == true) { # if need to debug then print coordinates
    echo 'DeltaX=' . $DeltaX . ', DeltaY=' . $DeltaY . '.<BR>'; # print coodinates
  } # if ($NeedDebug == true)

#----------------------------------------------------------------------------------------------
  
  if ($DeltaX > $DeltaY) { # if width of letter more height
  
    for ($For2 = 0; $For2 <= $DeltaX; $For2++) { # cycle points of width
  if ($DotX1 >= $DotX2) { # if position x1 more or equal position x2
  
    if ($DotY1 < $DotY2) { # if position y1 less position y2
      $TmpInt = round($DeltaY * (($DeltaX - $For2) / $DeltaX)); # set y coodinate
	} else { # if ($DotY1 < $DotY2)
	  $TmpInt = round($DeltaY * ($For2 / $DeltaX)); # set y coodinate
	} # if ($DotY1 < $DotY2) else

  } else { # if ($DotX1 >= $DotX2)
  
    if ($DotY1 >= $DotY2) { # if position y1 more position y2
      $TmpInt = round($DeltaY * (($DeltaX - $For2) / $DeltaX)); # set y coodinate
	} else { # if ($DotY1 >= $DotY2)
	  $TmpInt = round($DeltaY * ($For2 / $DeltaX)); # set y coodinate
	} # if ($DotY1 >= $DotY2) else

  } # if ($DotX1 >= $DotX2) else

      if ($NeedDebug == true) { # if need to debug
	    echo 'Y' . $For2 . '=' . $TmpInt . ', '; # print y coodinate
      }	# if ($NeedDebug == true)
  
  $Line[$FromY + $TmpInt][$FromX + $For2 - 1] = $DrawChar; # draw char on canvas 
    } # for ($For2 = 0; $For2 <= $DeltaX; $For2++) 

  } else { # if ($DeltaX > $DeltaY)  
  
    for ($For2 = 0; $For2 <= $DeltaY; $For2++) { # cycle points of height
  if ($DotY1 >= $DotY2) { # if position y1 more or equal position y2
  
    if ($DotX1 < $DotX2) { # if position x1 less position x2
      $TmpInt = round($DeltaX * (($DeltaY - $For2) / $DeltaY)); # set x coodinate
	} else { # if ($DotX1 < $DotX2)
	  $TmpInt = round($DeltaX * ($For2 / $DeltaY)); # set x coodinate
	} # if ($DotX1 < $DotX2) else

  } else { # if ($DotY1 >= $DotY2)
  
    if ($DotX1 >= $DotX2) { # if position x1 more or equal position x2
      $TmpInt = round($DeltaX * (($DeltaY - $For2) / $DeltaY)); # set x coodinate
	} else { # if ($DotX1 >= $DotX2)
	  $TmpInt = round($DeltaX * ($For2 / $DeltaY)); # set x coodinate
	} # if ($DotX1 >= $DotX2) else

  } # if ($DotY1 >= $DotY2) else

      if ($NeedDebug == true) { # if need to debug
  	    echo 'X' . $For2 . '=' . $TmpInt . ', '; # print x coodinate
      } # if ($NeedDebug == true)
  
  $Line[$FromY + $For2][$FromX + $TmpInt - 1] = $DrawChar; # draw char on canvas
    } # for ($For2 = 0; $For2 <= $DeltaY; $For2++)	

  } # if ($DeltaX > $DeltaY) else
  
#----------------------------------------------------------------------------------------------
  
  if ($NeedDebug == true) { # if need to debug
    echo '<BR>'; # print line break
  } # if ($NeedDebug == true) 
} # for ($For1 = 1; $For1 <= $DrawCount; $For1++)

#==============================================================================================

  $FuncString = ""; # clear canvas line

  for ($For1 = 1; $For1 <= $CanvasHeight; $For1++) { # cycle draw lines
    $TmpString = $Line[$For1]; # set draw line
$TmpInt = strlen($TmpString); # set length of draw line

    if ($TmpInt < $OriginX) { # if length of draw line less right side of canvas
  for ($For2 = $TmpInt; $For2 < $OriginX; $For2++) { # cycle symbols of draw line
    $TmpString = $TmpString . $SpaceChar; # add space to draw line
  }	# for ($For2 = $TmpInt; $For2 < $OriginX; $For2++)
} # if ($TmpInt < $OriginX)

$TmpInt = strlen($CanvasBackChars) - 1; # set length of background string of symbols

    for ($For2 = 0; $For2 < $OriginX; $For2++) { # cycle symbols of draw line
      if ($TmpString[$For2] == $SpaceChar) { # if symbol is space char
    $TmpString[$For2] = $CanvasBackChars[rand(0, $TmpInt)]; # randomize space char
  } # if ($TmpString[$For2] == $SpaceChar)
} # for ($For2 = 0; $For2 < $OriginX; $For2++)

$TmpInt = strlen($CanvasFrontChars) - 1; # set length of front string of symbols

for ($For2 = 0; $For2 < $OriginX; $For2++) { # cycle symbols of draw line
      if ($TmpString[$For2] == $DrawChar) { # if symbol is draw char
    $TmpString[$For2] = $CanvasFrontChars[rand(0, $TmpInt)]; # randomize draw char
  } # if ($TmpString[$For2] == $DrawChar)
    } # for ($For2 = 0; $For2 < $OriginX; $For2++)

$TmpString = str_replace(" ", " ", $TmpString); # change spaces to idents
$FuncString = $FuncString . $TmpString . '<BR>'; # add draw line to canvas line
  } # for ($For1 = 1; $For1 <= $CanvasHeight; $For1++)

  return '<SPAN STYLE="font-family: Lucida Console, Terminal, Courier, Monospace;'
  . ' font-size: ' . $FontSize . '">' . $FuncString . '</SPAN>'; # return canvas line
} # function ShowCaptcha($CaptchaText)

#==============================================================================================

?>

18928_.zip

Link to comment
Share on other sites

It looked pretty nice. If there is no/little software written for this type of captcha code, can't one just parse the text and create an image out of it? I guess you in some ways have made it so they don't need to parse an image, and just text instead.

 

In any case, this message is riddled with incorrect spelling (I'm not saying I'm a whole lot better, but I think it should be on the register page):

"Welcome! This site provides more securer private communications between people. All messages transmit by the internet and store in the database in encrypted format. All mathematic operations execute by client (internet browser), not by server. For text encrypting this forum uses AES (Rijndael) 256 CTR (Counter mode), symmetric military-class encryption (USA) 2012, and for passwords exchange between users - RSA (Rivest-Shamir-Adleman) 768-2048, one of the best asymmetric ciphers at present time. Here you can create your own forums and discuss with your friends any topics securely. Nobody (even administrator) can not read your closed messages. Register and join to encrypted community!"

 

 

"Nobody (even administrator) can not read your closed messages."

With other words, everyone can read all my closed messages, even the administrator (orly).

 

"All mathematic operations execute by client (internet browser), not by server."

I'm not so sure this is entirely true.

 

Sorry, please don't take it in the wrong way, I just want to help! I'm pretty sure your primary language is not English, probably east in Europe. :)

Link to comment
Share on other sites

It is readable now, yes. Though, my concerns still stand. Relying upon the client for the availability of security measures isn't a very good one, and you still don't have an alternative for those who can't read it.

That said, it seems to keep the formatting in links as well, so it should be reasonably consistent between systems now.

 

I'm naturally very skeptic to anything home-grown when it comes to security measures, simply because there are a lot of people (usually smarter than any of us) that has devoted a lot of time and energy to come up with the existing solutions. Time and energy they have spent in making sure that it's as secure as possible.

Any one person can easily make a security measure that s/he cannot crack themselves, but that doesn't mean that it's secure. Just that the author has reached the end of his or hers knowledge; And there are always people out there that knows more, especially those with bad intentions. That's why you really need to have this solution tested, by people who knows how to attack CAPTCHA-solutions.

 

PS: This would have done quite well as a class, with proper getters and setters for the configuration. Would make the code a bit more cohesive, and easier to use.

Link to comment
Share on other sites

"Nobody (even administrator) can not read your closed messages."

With other words, everyone can read all my closed messages, even the administrator (orly).

 

"All mathematic operations execute by client (internet browser), not by server."

I'm not so sure this is entirely true.

 

Sorry, please don't take it in the wrong way, I just want to help! I'm pretty sure your primary language is not English, probably east in Europe. :)

Thank you for help. I changed "Nobody" to "Anybody" and added "cryptographic" to "All mathematic operations".

Link to comment
Share on other sites

It looked pretty nice. If there is no/little software written for this type of captcha code, can't one just parse the text and create an image out of it? I guess you in some ways have made it so they don't need to parse an image, and just text instead.

Even spammer will convert this text based image to bitmap file, anyway it will be difficulty task for OCR system to read captcha symbols from this bitmap file.

Link to comment
Share on other sites

It is readable now, yes.

It is good.

 

Though, my concerns still stand. Relying upon the client for the availability of security measures isn't a very good one, and you still don't have an alternative for those who can't read it.

That said, it seems to keep the formatting in links as well, so it should be reasonably consistent between systems now.

 

I'm naturally very skeptic to anything home-grown when it comes to security measures, simply because there are a lot of people (usually smarter than any of us) that has devoted a lot of time and energy to come up with the existing solutions. Time and energy they have spent in making sure that it's as secure as possible.

Any one person can easily make a security measure that s/he cannot crack themselves, but that doesn't mean that it's secure. Just that the author has reached the end of his or hers knowledge; And there are always people out there that knows more, especially those with bad intentions. That's why you really need to have this solution tested, by people who knows how to attack CAPTCHA-solutions.

You are right, but I had not opportunity to use graphic captcha. Text based captcha is more faster and can be used on slow free servers. I think that ConsoleCaptcha is optimaly solution for free hostings. I guess that ConsoleCaptcha is more safe and reliable than text captchas based on stupid questions like as "one plus one = ?".

 

PS: This would have done quite well as a class, with proper getters and setters for the configuration. Would make the code a bit more cohesive, and easier to use.

Yes, so far ConsoleCaptcha is for programmers which have at least one convolution of the brain. :D May be, I will improve ConsoleCaptcha later.

Link to comment
Share on other sites

It looked pretty nice. If there is no/little software written for this type of captcha code, can't one just parse the text and create an image out of it? I guess you in some ways have made it so they don't need to parse an image, and just text instead.

Even spammer will convert this text based image to bitmap file, anyway it will be difficulty task for OCR system to read captcha symbols from this bitmap file.

 

No, it wont

 

On that note, it would probably be easier to simply grab the raw data and reverse engineer your algorithm

Link to comment
Share on other sites

Hi VanDerSaAr

 

I use a math captcha locally that randomly spits out either text or the numeral for each place....

 

I then also add ONE hidden (via CSS) form element titled something like URL or link and check to see if that field is empty prior to submission.

 

Never get spam.

 

Ive also employed Key Captcha with great success though its not local

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.