필요 한 것 이 있 습 니 다. 파충류 방지 양식 을 제출 하 는 인증 코드 문제 입 니 다.
그래서 관련 자 료 를 수집 해 보 니 오래된 자료 가 많 았 다.거의 07 년.
예 를 들 면:
http://babo.iteye.com/blog/72298 대부분의 검증 방법 은 Rmagick 으로 생 성 되 는데, 이 는 보통 두 가지 문제 가 있 을 수 있다.
1. Rmagick 의 메모리 문제
2. 검증 할 때마다 생 성
그렇다면 현재 유행 하 는 인증번호 솔 루 션 은 어 떨 까?
그래서 자신 이 긁 어 모 은 물건 을 나열 했다.
방안 1. 가장 선 호 하 는 해결 방안 은 이 서 비 스 를 클 라 우 드 서비스 제공 업 체 에 맡 기 는 것 이 유행 추세 이다.우리 가 invoice 에 피드백 을 건 네 주 는 것 과 같다. recaptcha 는 인증 코드 를 전문 적 으로 향상 시 키 는데 첫 번 째 유행 하 는 인증 코드 플러그 인 은 recaptcha 를 이용 한 것 입 니 다.
이런 장점 은 뚜렷하게 사용 할 수 있 고 매우 간단 하 며 전문 적 인 공급 자 도 효과 가 좋다.
대체로 다음 과 같이 사용한다.
script/plugin install git://github.com/ambethia/recaptcha.git
API 키 설정
recaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
environment. rb 에서 도 설정 할 수 있 습 니 다.
ENV['RECAPTCHA_PUBLIC_KEY'] = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
보기 에 태그 추가
recaptcha_tags
다음 인자 지원
인용 하 다.
:ssl: Uses secure http for captcha widget (default false)
:noscript: Include
content (default true) :display: Takes a hash containing the theme and tabindex options per the API. (default nil) :ajax: Render the dynamic AJAX captcha per the API. (default false) :public_key: Your public API key, takes precedence over the ENV variable (default nil) :error: Override the error code returned from the reCAPTCHA API (default nil) controller 에서 다음 을 검증 합 니 다: respond_to do |format|
if verify_recaptcha(:model => @post, :message => "Oh! It's error with reCAPTCHA!") && @post.save
# ...
else
# ...
end
end
방안 2: 필요 한 인증 코드 그림 을 무 작위 로 생 성하 고 사용 할 때 직접 검증 합 니 다. 이렇게 하면 Rmagick 의 메모리 문 제 를 해결 할 수 있 고 사용자 인증 은 그 당시 에 그림 을 만 들 지 않 아 도 된다. 아래 와 같이 사용: 다음 설치 에 따라 Rmagickhttp://rmagick.rubyforge.org/install-faq.html ubuntu 는 다음 과 같 습 니 다: 인용 하 다. Liux 에서 그림 을 만 들 려 면 이미지 처리 소프트웨어 인 ImageMagick 의 Ruby 언어 RMagick 라 이브 러 리 지원 이 필요 합 니 다.RMagick 을 설치 하 는 것 이 가장 번 거 로 워 서 나 는 N 여 자 료 를 찾 아 N 번 을 시험 해 보고 나 서 야 설치 에 성공 했다. 1. ImageMagick: sudo apt - get 설치 imagemagick 2. 설치 결과 보기: dpkg - l | grep magick 3. 패키지 목록 업데이트: sudo apt - get update 4. 그림 처리 패키지 libmagick9 - dev 설치: sudo apt - get install libmagick9 - dev ruby 1.8 - dev 5. 인터페이스 패키지 설치 RMagick: sudo gem install rmagick 6. 설명: 문제 나 오류 가 발생 하면 다음 명령 을 실행 하 십시오: sudo apt - get remove -- purge libmagick 9 - dev irb 에서 require 'RMagick'.트 루 로 돌아 가면 설치 에 성 공 했 음 을 표시 합 니 다. 플러그 인 설치script/plugin install git@github.com:zendesk/captcha.git
environment. rb 수정#environment.rb
CAPTCHA_SALT = 'Something really random here'
그림 생 성: 프로젝트 루트 디 렉 터 리, 명령 행 실행rake captcha:generate COUNT=250
다음 매개 변 수 를 가 져 올 수 있 습 니 다: 인용 하 다. COUNT - the number of images to generate, default 3 IMAGE_HEIGHT - the height of the captcha image in pixels, default 50 IMAGE_WIDTH - the width of the captcha image in pixels, default 260 CAPTCHA_LENGTH - the number of characters in the captcha, default 5 FILE_FORMAT - the file type of the captcha image (png or gif) 보기 표시: 인증번호 표시
<%= captcha_block %>
인증 코드 에 표 시 된 스타일 을 변경 하려 면 captcha 를 참조 하 십시오.helper.rb Controller 에서 다음 을 검증 합 니 다.
PostController < ApplicationController
validates_captcha
def create
...
if captcha_validated?
...
else
...
end
end
end
그 중 생 성 된 그림 은 미니 magick 을 사용 할 수 있 습 니 다. 프로젝트 3. 그림 생 성 검증 방식 을 사용 하지 않 습 니 다. script/plugin install http://code.subwindow.com/negative_captcha
컨트롤 러 에 리 셋 추가 before_filter :setup_negative_captcha, :only => [:new, :create]
대응 하 는 실행 방법 은 다음 과 같다. private
def setup_negative_captcha
@captcha = NegativeCaptcha.new(
:secret => NEGATIVE_CAPTCHA_SECRET, #A secret key entered in environment.rb. 'rake secret' will give you a good one.
:spinner => request.remote_ip,
:fields => [:name, :email, :body], #Whatever fields are in your form
:params => params)
end
논리 부분 검증 def create
@comment = Comment.new(@captcha.values) #Decrypted params
if @captcha.valid? && @comment.save
redirect_to @comment
else
flash[:notice] = @captcha.error if @captcha.error
render :action => 'new'
end
end
View 디 스 플레이 와 폼 은 다음 과 같 습 니 다. <% form_tag comments_path do -%>
<%= negative_captcha(@captcha) %>
<ul class="contact_us">
<li>
<label>Name:</label>
<%= negative_text_field_tag @captcha, :name %>
</li>
<li>
<label>Email:</label>
<%= negative_text_field_tag @captcha, :email %>
</li>
<li>
<label>Your Comment:</label>
<%= negative_text_area_tag @captcha, :body %>
</li>
<li>
<%= submit_tag %>
</li>
</ul>
<% end -%>
마지막 으로 인증 코드 의 스타일 에 대해 서 는 미니 magick 을 사용 하거나 다음 과 같이 더 예 쁘 게 고 칠 수 있 습 니 다.
require 'rubygems'
require 'RMagick'
class ProofImage
include Magick
attr_reader :text, :image
Jiggle = 15
Wobble = 15
def initialize(len=4)
chars = ('a'..'z').to_a # + ('0'..'9').to_a
text_array=[]
1.upto(len) {text_array << chars[rand(chars.length)]}
#background_type = "granite:" #花岗岩
#background_type = "netscape:" #彩条
#background_type = "xc:#EDF7E7" #指定背景色,例:xc:red
#background_type = "null:" #纯黑
granite = Magick::ImageList.new('null:')
canvas = Magick::ImageList.new
canvas.new_image(32*len, 50, Magick::TextureFill.new(granite))
gc = Magick::Draw.new
gc.font_family = 'times'
gc.pointsize = 40
cur = 10
text_array.each{|c|
rand(10) > 5 ? rot=rand(Wobble):rot= -rand(Wobble)
rand(10) > 5 ? weight = NormalWeight : weight = BoldWeight
gc.annotate(canvas,0,0,cur,30+rand(Jiggle),c){
self.rotation=rot
self.font_weight = weight
self.fill = 'green'
}
cur += 30
}
@text = text_array.to_s
@image = canvas.to_blob{
self.format="GIF"
}
#生成图片文件
#text.text(0, 0, " ")
#text.draw(canvas)
#canvas.write('test.gif') #图片位于项目根目录下。也可以使用linux中的绝对路径如:/home/chengang/test.gif
end
end
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Linux Makinalarda NFS Sunucu Mount Etme(데비안 및 RPM)
Debian은 Red Hat 탭과 Linux NFS Sunucu 라이브러리를 모두 지원합니다.
NFS 지불 방법은 클라이언트 제작자가 사용하지 않는 기본 설정을 유지하는 것입니다.
Örnek verecek olurs...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.