Skip to content

Scala captcha, or Simple captcha, and probably both Simple Scala (functional) captcha.

Notifications You must be signed in to change notification settings

playalot/scaptcha

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCaptcha

Scala captcha, or Simple captcha, and probably both Simple Scala (functional) captcha.

Build Status

Usage

SBT

To use SCaptcha in your SBT (or Play) projects, you can either built it yourself (see thereafter), or add following resolver:

resolvers += "Applicius Snapshots" at "https://raw.github.com/applicius/mvn-repo/master/snapshots/"

libraryDependencies += "scaptcha" %% "scaptcha" % "1.0-SNAPSHOT"

Playframework

It can be integrated as Play controller.

First in view (e.g. temporal catcha of 8 characters):

  @defining(Captcha.temporalCaptcha(8)) { captcha =>
  <form action="yourAction">
    <img src="@[email protected](captcha.value)" />
    <input type="text" name="passphrase" value="" />
    <input type="hidden" name="captchaCode" value="@captcha.code" />
  </form>
  }

Then in controllers:

package controllers

import play.api.Play
import play.api.libs.iteratee.Enumerator
import play.api.mvc.{ Action, Controller }

object Captcha extends Controller with scaptcha.Captcha {
  // Use Play application secret as scaptcha seed
  lazy val seed = Play.current.configuration.
    getString("application.secret").map(_.filter(_ != '/')).
    getOrElse(System.identityHashCode(this).toString)

  def image(text: String) = Action {
    val imageStream = textImage(text)

    Ok.stream(Enumerator.fromStream(imageStream)).as("image/png")
  }
}

Finally, when form including captcha is submitted, it can be checked easily:

Captcha.matches(captchaCode/* catcha.code */, length/* of captcha.value */, passphrase) // Boolean

Build

sbt package

About

Scala captcha, or Simple captcha, and probably both Simple Scala (functional) captcha.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 62.8%
  • Java 37.2%