<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vinsol - Leading Ruby on Rails Development and Consulting Firm in India &#187; validations</title>
	<atom:link href="http://vinsol.com/blog/category/validations/feed/" rel="self" type="application/rss+xml" />
	<link>http://vinsol.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 26 Jul 2010 08:37:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Captcha in Ruby on Rails &#8211; Customize the use of captcha in the plugin validates_captcha</title>
		<link>http://vinsol.com/blog/2006/10/24/captcha-in-ruby-on-rails-customize-the-use-of-captcha-in-the-plugin-validates_captcha/</link>
		<comments>http://vinsol.com/blog/2006/10/24/captcha-in-ruby-on-rails-customize-the-use-of-captcha-in-the-plugin-validates_captcha/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 18:59:40 +0000</pubDate>
		<dc:creator>Sur Max</dc:creator>
				<category><![CDATA[captcha]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[validations]]></category>

		<guid isPermaLink="false">http://ajaxonrails.wordpress.com/2006/10/24/captcha-in-ruby-on-rails-customize-the-use-of-captcha-in-the-plugin-validates_captcha/</guid>
		<description><![CDATA[To implement captcha in RubyonRails, validates_captcha plugin can be a good option but a small customization i need with this plugin was to use it on some specific action and not to be validated the captcha field every time an instance of the model is saved or updated.
Here is a small work-around for its customization&#8230;
How [...]


Related posts:<ol><li><a href='http://vinsol.com/blog/2010/04/01/ssl-checklist-for-rails-applications/' rel='bookmark' title='Permanent Link: SSL checklist for Ruby on Rails Applications'>SSL checklist for Ruby on Rails Applications</a> <small>Cross posted from darthsid The purpose of SSL is to...</small></li>
<li><a href='http://vinsol.com/blog/2010/04/09/introduction-to-active-scaffold-part-i/' rel='bookmark' title='Permanent Link: Introduction to Active Scaffold  Part I'>Introduction to Active Scaffold  Part I</a> <small>I originally wrote this article for fifth issue of Rails...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'>
<p>Hello Everyone !!<br />
I have released a captcha plugin <a href="http://expressica.com/2007/02/06/simple-captcha-released-the-captcha-for-rails-applications/"><b>Simple Captcha</b></a>. It is really simple to implement, and provides a cool feature of multiple styles of images.</p>
<p>
<hr />
<b>Previous Post for validates_captcha</b></p>
<hr />
To implement captcha in RubyonRails, <a href="http://svn.2750flesk.com/validates_captcha"><strong>validates_captcha</strong></a> plugin can be a good option but a small customization i need with this plugin was to use it on some specific action and not to be validated the captcha field every time an instance of the model is saved or updated.<br />
Here is a small work-around for its customization&#8230;<br />
<strong>How to use customized captcha in RoR ?</strong><br />
Install the plugin validates_captcha in your rails application by running this command from the root of your application</p>
<pre>
ruby script/plugin install http://svn.2750flesk.com/validates_captcha</pre>
<p>Make sure that you can now see the directory <strong>vedor/plugins/validates_captcha</strong>.</p>
<p>Now run these commands from your application root to make the image and data directories</p>
<pre>
  ruby script/generate captcha store_directory
  ruby script/generate captcha image_directory</pre>
<p>Here is the complete <a href="http://dev.2750flesk.com/validates_captcha/"><strong>API</strong></a> for the usage of this plugin. I am describing the same idea as given in this API but in a bit more specific means.</p>
<p>Lets consider a model <strong>User</strong> in which we will implement the captcha.<br />
Add the following code in the file <strong>app/models/user.rb</strong></p>
<pre>
  class User &lt; ActiveRecord::Base

    validates_captcha :if =&gt; :request_captcha_validation?
    attr_accessor :request_captcha_validation

    def request_captcha_validation?
      (self.request_captcha_validation==true)? true : false
    end

  end</pre>
<h3>Handle View and Controller</h3>
<p><strong>Add the code in the view inside your existing form.</strong></p>
<pre>
  &lt;% c = prepare_captcha :type =&gt; :image -%&gt;
  &lt;%= captcha_hidden_field c, 'user' %&gt;
  &lt;%= captcha_image_tag c %&gt;
  &lt;%= captcha_label 'user', 'Type in the text from the image above' %&gt;
  &lt;%= captcha_text_field 'user' %&gt;</pre>
<p><strong>Your controller will look like</strong></p>
<pre>
  def save
    # the line in bold represents that you need captcha validation.
    # if captcha validation is not required then remove this line from your controller.
    @user = User.new(params[:user])
    <strong>@user.request_captcha_validation = true</strong>
    @user.save
  end</pre>
<p>However image is too noisy and it contains repeated strings.<br />
To improve the quality of images generated by the plugin validates_captcha visit <a href="http://ajaxonrails.wordpress.com/2006/10/17/how-to-improve-the-image-quality-and-generate-random-string-image-in-the-plugin-validates_captcha/"><strong>Here</strong></a>.</p>
</div>


<p>Related posts:<ol><li><a href='http://vinsol.com/blog/2010/04/01/ssl-checklist-for-rails-applications/' rel='bookmark' title='Permanent Link: SSL checklist for Ruby on Rails Applications'>SSL checklist for Ruby on Rails Applications</a> <small>Cross posted from darthsid The purpose of SSL is to...</small></li>
<li><a href='http://vinsol.com/blog/2010/04/09/introduction-to-active-scaffold-part-i/' rel='bookmark' title='Permanent Link: Introduction to Active Scaffold  Part I'>Introduction to Active Scaffold  Part I</a> <small>I originally wrote this article for fifth issue of Rails...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://vinsol.com/blog/2006/10/24/captcha-in-ruby-on-rails-customize-the-use-of-captcha-in-the-plugin-validates_captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Regular Expression in Ruby on Rails — Regexp for Password Validation</title>
		<link>http://vinsol.com/blog/2006/10/19/using-regular-expression-in-ruby-on-rails-%e2%80%94-regexp-for-password-validation/</link>
		<comments>http://vinsol.com/blog/2006/10/19/using-regular-expression-in-ruby-on-rails-%e2%80%94-regexp-for-password-validation/#comments</comments>
		<pubDate>Thu, 19 Oct 2006 10:51:35 +0000</pubDate>
		<dc:creator>Sur Max</dc:creator>
				<category><![CDATA[password]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[validations]]></category>

		<guid isPermaLink="false">http://ajaxonrails.wordpress.com/2006/10/19/using-regular-expression-in-ruby-on-rails-regex-for-password-validation/</guid>
		<description><![CDATA[A regular expression (abbreviated as regexp or regex, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns. Many programming languages [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><p>A <strong>regular expression</strong> (abbreviated as <strong>regexp</strong> or <strong>regex</strong>, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns. Many programming languages support regular expressions for string manipulation. Ruby has a strong Regular Expression engine built directly as a class of Ruby Programming language as <strong>Regexp</strong><br />
Here we will go through an example which will validate the password string.<br />
Lets say we have to implement the following validations to validate a password&#8230;</p>
<ul>
<li>Password should contain atleast one integer.</li>
<li>Password should contain atleast one alphabet(either in downcase or upcase).</li>
<li>Password can have special characters from <strong>20</strong> to <strong>7E</strong> ascii values.</li>
<li>Password should be minimum of 8 and maximum of 40 cahracters long.</li>
</ul>
<p>To fulfill above requirements we can have a regular expression like&#8230;<br />
<code> </code></p>
<pre>
<h3>/^(?=.*&#92;d)(?=.*([a-z]|[A-Z]))([&#92;x20-&#92;x7E]){8,40}$/</h3>
</pre>
<p>in ruby programming language we can have a number of ways to define this regular expression as&#8230;<br />
■ reg = Regexp.new(&#8221;^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,40}$&#8221;)<br />
or<br />
■ reg = %r(^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,40}$)<br />
or simply<br />
■ reg = /^(?=.*\d)(?=.*([a-z]|[A-Z]))([\x20-\x7E]){8,40}$/</p>
<p>Now look what exactly this regex is doing&#8230;<br />
<strong>(?=.*\d)</strong> shows that the string should contain atleast one integer.<br />
<strong>(?=.*([a-z]|[A-Z</strong><strong>]))</strong> shows that the string should contain atleast one alphabet either from downcase or upcase.<br />
<strong>([\x20-\x7E])</strong> shows that string can have special characters of ascii values 20 to 7E.<br />
<strong>{8,40}</strong> shows that string should be minimum of 8 to maximum of 40 cahracters long.<br />
We can simply use this regular expression for manual handling of password in an action as&#8230;<br />
<code></code></p>
<pre>
def validate_password(password)

  reg = /^(?=.*&#92;d)(?=.*([a-z]|[A-Z]))([&#92;x20-&#92;x7E]){8,40}$/

return (reg.match(password))? true : false

end</pre>
<h3>How to implement this regular expression in a model class in ruby on rails for password validation ?</h3>
<p>To implement this regular expression in the model class in the rails way we can do it  like&#8230;<br />
<code></code></p>
<pre>
class MyModel

  validates_format_of :password, :with =&gt; /^(?=.*&#92;d)(?=.*([a-z]|[A-Z]))([&#92;x20-&#92;x7E]){8,40}$/

end</pre>
</div>]]></content:encoded>
			<wfw:commentRss>http://vinsol.com/blog/2006/10/19/using-regular-expression-in-ruby-on-rails-%e2%80%94-regexp-for-password-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
