all repos — captcha @ d7cb604d49c3777d159741e1df389c6c540310f8

Go package captcha implements generation and verification of image and audio CAPTCHAs.

d7cb604d
Add copyright headers.

sounds.go doesn't have a copyright header, because the file is generated
by a program. I don't want to make it output the copyright header,
because users can generate sounds themselves, and the copyright status
of such generated files can be different.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 24 May 2011 11:05:31 +0200
7fee67a2
Better Russian sounds.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 12 May 2011 14:41:00 +0200
cacbe12b
generate: use filepath instead of path.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 12 May 2011 12:59:58 +0200
9d0ab4e0
generate: add new line after digitSounds.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 12 May 2011 12:43:22 +0200
663c7c10
Update README.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 23:40:00 +0200
0a3f3296
Mention Russian in package doc.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 23:29:46 +0200
1f906795
example: add language dropdown.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 23:27:57 +0200
cb56dd20
Add Russian sounds (ru).
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 23:10:29 +0200
7c629aef
Support other languages in audio captchas.

Server accepts parameter lang, e.g. xxx.wav?lang=en.
NewAudio and WriteAudio accept the target language.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 11 May 2011 22:16:35 +0200
34dcf8d1
Better error descriptions.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 08 May 2011 12:14:43 +0200
f0b06e6d
image: s/img/m/
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 08 May 2011 12:12:11 +0200
4559a6b5
Update example.wav.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 04 May 2011 17:30:58 +0200
0b62e127
audio: increase level of background sounds.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 04 May 2011 17:21:31 +0200
ebb75a0b
Update generate with new waveHeader.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 01 May 2011 13:37:58 +0200
05ff9ea7
audio: proper RIFF header generation.

At last!

[RIFF][following size][WAVE]fmt[...]...data[data size][padded data].

Also, update example.wav.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 01 May 2011 13:31:16 +0200
e6fb7340
audio: error handling; pad byte is 0, not 128.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 01 May 2011 12:48:01 +0200
ad3bc714
audio: write pad byte when data length is odd.

This is specified in RIFF format, but I forgot to implement.

     ckData  Binary data of fixed or variable size. The start of
	     ckData is word-aligned with respect to the start of the
	     RIFF file.  If the chunk size is an odd number of bytes, a
	     pad byte with value zero is written after ckData.  Word
	     aligning improves access speed (for chunks resident in
	     memory) and maintains compatibility with EA IFF.  The
	     ckSize value does not include the pad byte.

(From http://www.kk.iij4u.or.jp/~kondo/wave/mpidata.txt)
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 01 May 2011 12:33:27 +0200
796c18f3
image: rename a few variables.
Dmitry Chestnykh dmitry@codingrobots.com
Fri, 29 Apr 2011 15:26:14 +0200
f14d4a99
random: seed with Nanoseconds.
Dmitry Chestnykh dmitry@codingrobots.com
Fri, 29 Apr 2011 04:51:24 +0200
c087adeb
Remove dependency on uniuri. Add random.go.

Captcha ids are now 20 characters long.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 23:12:29 +0200
62d3514c
Add store set/collect benchmark.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 21:02:19 +0200
d6bfb3fd
image: forgot to use circleCount const in NewImage.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 20:29:34 +0200
0c420156
image: use paletted image.

This simplifies code and makes it faster. It also produces smaller PNGs.

Before:

captcha.BenchmarkNewImage	500	 6198230 ns/op
captcha.BenchmarkImageWriteTo	100	17517110 ns/op   0.14 MB/s

After:

captcha.BenchmarkNewImage	500	 3869968 ns/op
captcha.BenchmarkImageWriteTo	200	 7237604 ns/op   0.23 MB/s

(Core 2 Duo @ 2.26 GHz, MacBook)

Currently the background is white, not transparent, because PNG encoder
doesn't support paletted images with alpha channel.

Submitted CL: http://codereview.appspot.com/4432078

Change alpha to 0x00 once it's accepted to make captcha transparent.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 20:09:50 +0200
fe75d4b6
capgen: update for StdLength -> DefaultLen rename.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 15:58:04 +0200
aef40a9c
Report MB/s in audio and image benchmarks.

Also, audio benchmark uses the new ioutil.Discard.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 14:58:53 +0200
436e363f
audio: do not change final background level.

Instead, change level of individual reversed sounds when making
background to the appropriate values.

This speeds up makeBackgroundSound ~3%.

Before and after.
captcha.BenchmarkNewAudio      50  30436940 ns/op
captcha.BenchmarkNewAudio      50  29435780 ns/op

Also, level up white noise a bit.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 11:06:56 +0200
b9845ccf
audio: preallocate reverse sounds (~5% speed up).

Also:
- use ranges everywhere
- optimize makeWhiteNoise a bit

Before and after:
captcha.BenchmarkNewAudio      50  32128580 ns/op
captcha.BenchmarkNewAudio      50  30436940 ns/op
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 01:20:11 +0200
6ca6c386
Add image and audio benchmarks.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 01:19:56 +0200
d4eb7a3c
Update README again.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 00:13:39 +0200
b4213101
Update README.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 00:12:19 +0200
a85bba10
Fix tests.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 28 Apr 2011 00:02:57 +0200
5192a066
image: remove random variations in drawDigit's x,y.

For the standard size and width with new font they no longer had any
effect anyway (were always +0).
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:37:21 +0200
de409bf9
image: precalculate dx in distort and strikeThrough.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:28:27 +0200
a7f7c639
server: better names for arguments to Server.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:17:28 +0200
647026ab
New now returns captcha with default length.

NewLen is now like the old New (accepts captcha length as the argument).
Also, rename StdLength to DefaultLen.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:11:38 +0200
c5afad97
captcha: remove Collect method.

Garbage collection is an internal detail of a Store, and requiring to
export this method seem to be not very useful.

The default memory store, of course, still has garbage collection, but
it's not the unexported method, called in Set as usual.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:00:06 +0200
e136731c
image: fix terminology again.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 21:20:21 +0200
719496cd
image: refactor, fix terminology.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 21:14:22 +0200
41391fd0
Update README again.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 20:54:49 +0200
d2a6c654
Update README.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 20:53:41 +0200
79c3ed21
Update example.png.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 20:51:13 +0200
1b34f643
image: new wave distortion, and strike-through.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 20:44:24 +0200
d6b0f36e
example: print the address of server.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 20:43:43 +0200
c6bfbfa6
font: more readable 1 and 7.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 19:16:35 +0200
307ecdad
image: use font with better resolution.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 18:41:58 +0200
b8bb54f6
image: simplify skew randomization.

Use rndf instead of rand.Float64 voodoo.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 15:55:36 +0200
a6788822
example: add "Try another one" link; ignore /xxx.

Only return page for root path /, return 404 for any other, such as
/favicon.ico.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 15:54:27 +0200
1f117474
server: fix "multiple response.WriteHeader calls".

The server no does nothing for errors other than ErrNotFound (for which
it calls http.NotFound). This is becase when getting error on writing,
we already wrote headers, so can't respond with status 500.

Possibly log errors in future?
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 15:52:32 +0200
3218681e
example: update with recent download changes.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 13:12:28 +0200
c72fa4f2
server: serve downloads from "/download/".

Also, refactor methods.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 13:09:22 +0200
6e79acad
Move server parts to server.go.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 12:30:13 +0200
316aacb9
Server: disable uppercase extensions (.PNG, .WAV).

Also fixes comment typo.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 00:41:52 +0200
0052db45
example: use io instead of fmt; add error handling.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 21:32:16 +0200
885d67a6
store: fix potential race.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 19:16:09 +0200
60d32e9f
store: rename ids to digitsById, exp to idByTime.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 18:57:16 +0200
a0a9c943
Update docs.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 18:36:54 +0200
c833d164
Add examples captchas.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 18:34:52 +0200
5c81f018
Use new GitHub-flavored Markdown syntax for types.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 15:22:52 +0200
31e7bb63
Rename README to README.md
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 14:59:32 +0200
ca43a14c
Add README.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 14:58:42 +0200
d671ee04
Example: make HTML5 valid.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 13:18:06 +0200
b6b09caf
Example: implement reloading; fix audio in Safari.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 13:14:01 +0200
0476dc3b
Server: reload captcha when given ?reload=x in URL.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 13:04:11 +0200
8d3ca40d
Add notice about Chrome 10 bug to BUGS.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 23:53:22 +0200
a9e88462
Add notice about Image.WriteTo to BUGS.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 23:43:27 +0200
4b8382af
Remove "Std" from StdCollectNum and StdExpiration.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 23:35:53 +0200
dab96732
Add Store interface.

Standard storage is now known as memoryStore (created with
NewMemoryStore exported function). It's still default, however there's
now an option to replace it with a custom store by implementing Store
interface and calling SetCustomStore.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 23:25:39 +0200
230b62a6
Add example HTTP server that uses the package.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 17:34:47 +0200
fe4a5975
Thinner strike-through on captcha image.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 12:26:12 +0200
8a2b5ae5
Add Audio.EncodedLen. Workaround for Chrome WAV bug.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 02:16:01 +0200
d010e3f9
Add VerifyString function.
Dmitry Chestnykh dmitry@codingrobots.com
Mon, 25 Apr 2011 00:42:43 +0200
bd0535ea
Add CaptchaServer.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 23:57:29 +0200
4572d7de
Fix comments, apply gofmt.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 22:49:14 +0200
11dc0126
generate: rename to main.go, add Makefile.

Fix adding extra space in the generated sounds.go.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 21:54:32 +0200
2ef763a3
Rename cmd to capgen, originals to generate.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 21:45:37 +0200
5dd14861
Add captcha test.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 16:09:55 +0200
8779418c
Add store test.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 15:58:05 +0200
7b585d44
Fix collection (locking and getting next value).
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 15:53:45 +0200
90e4f749
newStore: accept collectNum and expiration time.

Prevoiusly, Expiration and CollectNum were hard-coded into store.go.
This change moves these constants to captcha.go (renaming to Std*), and
makes newStore accept them as arguments.

This will enable setting these paraments by package users sometime in
the future, if needed, and also allows testing of the store garbage
collection.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 15:19:49 +0200
9de0d066
Add ErrNotFound, return it from WriteAudio/Image.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 14:34:11 +0200
68d217e7
Export RandomDigits. Remove NewRandom* functions.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 13:30:31 +0200
c179a205
Rename "numbers" to "digits" everywhere.

Plus fix comments.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 13:23:17 +0200
2052308d
Set capacity for audio buffer. Rename makeStaticNoise to makeWhiteNoise.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 12:56:02 +0200
874a3063
Rearrange code and fix docs.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 21:20:12 +0200
8b932fcf
Implement a single captcha test command.

The new command replaces old test command-line utilities from cmd/image
and cmd/audio directories. It can now generate both image and audio
captchas, and accepts a few useful flags.

Edit .gitignore to reflect changes.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 21:17:23 +0200
e40250a1
Add NewRandomAudio function.

Audio test cmd now writes to stdout.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:53:26 +0200
79744759
Replace PNGEncode with WriteTo for Image.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:48:58 +0200
e3eb2248
Add WriteAudio function.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:44:02 +0200
5357b20f
Rename CaptchaImage -> Image, CaptchaAudio -> Audio.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:41:00 +0200
82004bd9
Apply gofmt; fix comment in generate.go.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 15:50:37 +0200
9ac4ea2b
Better randomize background and sounds.

Shorten intervals between prelude beeps.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 15:41:48 +0200
45c2a02d
Lower level of beep sound.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 15:39:51 +0200
8f4b2012
First version of audio captcha.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 13:13:51 +0200
3586f91d
Move image generation test program to cmd/image.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 11:24:17 +0200
778d34d6
image: move border calculation to calculateSizes().
Dmitry Chestnykh dmitry@codingrobots.com
Fri, 22 Apr 2011 00:05:19 +0200
452b826a
Fix comments.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 23:43:47 +0200
b5845762
Move rand initialization to image.go.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 23:08:58 +0200
8033b950
Clarify docs.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 23:07:23 +0200
d36aa1f3
image: refactor; add more color variations.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 22:43:25 +0200
aa0588b4
Refactor store into its own file.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 22:28:52 +0200
0674e88f
Accept the length of the random sequence of numbers.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 18:18:00 +0200
f9f7db1f
Call Collect on a separate goroutine.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 18:14:28 +0200
59a641ef
Update documentation.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 18:05:53 +0200
cbab3d06
cmd: use standard width and height for image.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 17:53:34 +0200
01012728
Document functions and types in captcha.go.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 17:53:08 +0200
bb39fc5c
Refactored image captcha ready, and documented.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 17:41:44 +0200
f1572d4d
Numbers are now laid out correctly.

Next commits will introduce perturbations.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 16:48:12 +0200
d88ce819
Started work on code cleanup.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 01:12:31 +0200
9da9f1ad
Gofmt font.go.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 20 Apr 2011 13:18:51 +0200
364b4304
Move image-related functions into image.go.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 20 Apr 2011 03:14:29 +0200
b04efdcc
Add line that strikes through digits.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 20 Apr 2011 03:05:45 +0200
caf79f3b
Reorganize code. Add storage.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 20 Apr 2011 01:24:30 +0200
69b50fb6
Initial version (numbers).
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 19 Apr 2011 20:32:40 +0200