Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116434
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/README.md b/README.md
index 96bd752..c229cca 100644
--- a/README.md
+++ b/README.md
@@ -1,37 +1,38 @@
# Captcha
This is a Elixir lib for generating captcha. No dependencies. It drawing captcha image with C code. No ImageMagick, No RMagick.
C code come from: [https://github.com/huacnlee/rucaptcha](https://github.com/huacnlee/rucaptcha)
<img src="https://cloud.githubusercontent.com/assets/5518/22151425/e02390c8-df58-11e6-974d-5eb9b1a4e577.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151427/e4939d92-df58-11e6-9754-4a46a86acea8.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151431/e494576e-df58-11e6-9845-a5590904c175.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151432/e495066e-df58-11e6-92b8-38b40b73aba0.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151428/e49404ee-df58-11e6-8e2d-8b17b33a3710.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151430/e4942406-df58-11e6-9ff8-6e2325304b41.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151429/e4941ae2-df58-11e6-8107-757296573b2f.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151433/e4c7c89c-df58-11e6-9853-1ffbb4986962.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151435/e4c97ea8-df58-11e6-8959-b4c78716271d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151436/e4cc09f2-df58-11e6-965c-673333b33c0d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151434/e4c87788-df58-11e6-9490-c255aaafce71.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151445/ee35ff66-df58-11e6-8660-a3673ef3f5ee.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151446/ee67b074-df58-11e6-9b95-7d53eec21c33.gif" width="150px" />
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add `captcha` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:captcha, "~> 0.1.0"}]
end
```
2. Ensure `captcha` is started before your application:
```elixir
def application do
[applications: [:captcha]]
end
```
## Usage
```elixir
+# allow customize receive timeout, default: 10_000
case Captcha.get() do
{:ok, text, img_binary } ->
# save text in session, then send img to client
{:timeout} ->
# log some error
end
```
diff --git a/lib/captcha.ex b/lib/captcha.ex
index 0d825d2..046ff1a 100644
--- a/lib/captcha.ex
+++ b/lib/captcha.ex
@@ -1,14 +1,16 @@
defmodule Captcha do
- def get() do
+ def get(timeout \\ 10_000) do
Port.open({:spawn, Path.join(:code.priv_dir(:captcha), "captcha")}, [:binary])
+ # Allow set receive timeout
receive do
{_, {:data, data}} ->
<<text::bytes-size(5), img::binary>> = data
{:ok, text, img }
+
other -> other
- after
- 10_000 -> { :timeout }
+ after timeout ->
+ { :timeout }
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Dec 1, 1:53 PM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41714
Default Alt Text
(3 KB)
Attached To
Mode
R13 elixir-captcha
Attached
Detach File
Event Timeline
Log In to Comment