two way crypt:
bcrypt-ruby
An easy way to keep your users’ passwords secure.
* bcrypt-ruby.rubyforge.org/
* github.com/codahale/bcrypt-ruby/tree/master
Why you should use bcrypt
If you store user passwords in the clear, then an attacker who steals a copy of your database has a giant list of emails and passwords. Some of your users will only have one password — for their email account, for their banking account, for your application. A simple hack could escalate into massive identity theft.
It‘s your responsibility as a web developer to make your web application secure — blaming your users for not being security experts is not a professional response to risk.
bcrypt allows you to easily harden your application against these kinds of attacks.
How to install bcrypt
You‘ll need a working compiler. (Win32 folks should use Cygwin or um, something else.)
How to use bcrypt in your Rails application
The User model
Creating an account
Authenticating a user
If a user forgets their password?
# assign them a random one and mail it to them, asking them to change it
How to use bcrypt-ruby in general
Check the rdocs for more details — http://bcrypt-ruby.rubyforge.org/classes/BCrypt.htmlBCrypt, http://bcrypt-ruby.rubyforge.org/classes/BCrypt/Password.htmlBCrypt::Password.
#http://crypt.rubyforge.org/blowfish.html #gem install crypt require 'crypt/blowfish' blowfish = Crypt::Blowfish.new("A key up to 56 bytes long") plainBlock = "ABCD1234" p plainBlock encryptedBlock = blowfish.encrypt_block(plainBlock) p encryptedBlock decryptedBlock = blowfish.decrypt_block(encryptedBlock) p decryptedBlock
bcrypt-ruby
An easy way to keep your users’ passwords secure.
* bcrypt-ruby.rubyforge.org/
* github.com/codahale/bcrypt-ruby/tree/master
Why you should use bcrypt
If you store user passwords in the clear, then an attacker who steals a copy of your database has a giant list of emails and passwords. Some of your users will only have one password — for their email account, for their banking account, for your application. A simple hack could escalate into massive identity theft.
It‘s your responsibility as a web developer to make your web application secure — blaming your users for not being security experts is not a professional response to risk.
bcrypt allows you to easily harden your application against these kinds of attacks.
How to install bcrypt
sudo gem install bcrypt-ruby
You‘ll need a working compiler. (Win32 folks should use Cygwin or um, something else.)
How to use bcrypt in your Rails application
The User model
require 'bcrypt' class User < ActiveRecord::Base # users.password_hash in the database is a :string include BCrypt def password @password ||= Password.new(password_hash) end def password=(new_password) @password = Password.create(new_password) self.password_hash = @password end end
Creating an account
def create @user = User.new(params[:user]) @user.password = params[:password] @user.save! end
Authenticating a user
def login @user = User.find_by_email(params[:email]) if @user.password == params[:password] give_token else redirect_to home_url end end
If a user forgets their password?
# assign them a random one and mail it to them, asking them to change it
def forgot_password @user = User.find_by_email(params[:email]) random_password = Array.new(10).map { (65 + rand(58)).chr }.join @user.password = random_password @user.save! Mailer.create_and_deliver_password_change(@user, random_password) end
How to use bcrypt-ruby in general
require 'bcrypt' my_password = BCrypt::Password.create("my password") #=> "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa" my_password.version #=> "2a" my_password.cost #=> 10 my_password == "my password" #=> true my_password == "not my password" #=> false my_password = BCrypt::Password.new("$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa") my_password == "my password" #=> true my_password == "not my password" #=> false
Check the rdocs for more details — http://bcrypt-ruby.rubyforge.org/classes/BCrypt.htmlBCrypt, http://bcrypt-ruby.rubyforge.org/classes/BCrypt/Password.htmlBCrypt::Password.
发表评论
-
使用 Capistrano 对rails app进行快速部署
2011-02-23 15:05 1834仅转载了,还没有用过,如果有问题可留言,大家一起讨论 在进行 ... -
ruby进行web serveice的方法
2011-02-15 14:37 868require 'soap/wsdlDriver' #url ... -
友好的登录系统
2011-01-28 10:54 715友好的登录系统 按照目前的代码,如果管理员尝试在未登录的状态下 ... -
第三版
2011-01-27 15:36 0view格式化价格 <%= number_to_curr ... -
用户操作数据库记录
2011-01-25 15:16 891今天我们看看怎样在数据库记录用户操作 db/migrate/0 ... -
Ruby中 respond_to? 和 send 的用法
2011-01-25 14:24 1299obj = Object.new if obj ... -
rails 路由
2011-01-25 14:17 11914 正则路由 Rails支持 ... -
rails 验证自定义方法
2011-01-25 11:37 1608可以自定义validate(), 这个方法在每次保存数据时都会 ... -
flash-notice自动消失
2011-01-25 11:12 1479flash 提示的自动消失: <body onloa ... -
开发环境页面直接调试
2011-01-25 11:06 706#首先,在layout里边的合适地方添加debug,并且使 ... -
对静态页面进行缓存
2011-01-24 14:35 969对于静态站点我们可以利用Rails的cache来管理,如在co ... -
rvm部署rails3和ruby192
2011-01-21 10:39 11201. Installing RVM $ sudo gem ... -
rails要理解
2011-01-18 10:57 658清单3 module Dictionary ... -
rails 加载不同插件设置
2010-12-31 14:49 418config.plugins = [ :all ] co ... -
参考rails 下拉
2010-12-31 14:47 708对于多数的model的select列表,我都会用model属性 ... -
自定义form提示
2010-12-31 10:53 740自定义form错误提示 application_contro ... -
提高rails开发模式下静态页加载速度
2010-12-31 10:44 902http://github.com/thedarkone/ra ... -
rails 连接多个数据库
2010-12-30 10:31 810首先在database.yml中加入以下代码,其中cg_clo ... -
瘦controller,富model
2010-12-28 14:02 778----先看这么一段rhtml代码:渲染模板中加入了这么多的逻 ... -
rake 命令一览
2010-12-28 11:21 1035rake db:abort_if_pending_migr ...
相关推荐
凯撒密码加密和解密python实现源码.zip凯撒密码加密和解密python实现源码.zip凯撒密码加密和解密python实现源码.zip凯撒密码加密和解密python实现源码.zip凯撒密码加密和解密python实现源码.zip凯撒密码加密和解密...
基于Python的凯撒密码加密和解密源码.zip基于Python的凯撒密码加密和解密源码.zip基于Python的凯撒密码加密和解密源码.zip基于Python的凯撒密码加密和解密源码.zip基于Python的凯撒密码加密和解密源码.zip基于Python...
内容包含凯撒密码一个加密函数,和一个解密函数,适用于有一些指定需求的人,如有问题请私信我。 恺撒密码(英语:Caesar cipher),或称恺撒加密、恺撒变换、变换加密,是一种最简单且最广为人知的加密技术。它是一...
本资源使用经典hill密码对输入的字符串进行加密和解密,加密矩阵可以根据自己的要求更改,加密过程中3个字母为一组,不足三个时,输出的解密后的字符串用哑文z补齐。下载解压后,导入MATLAB路径中,直接运行即可。...
总结来说,C语言实现的凯撒密码加密和解密程序提供了一个基础的加密示例,但在实际应用中需要进一步增强安全性,包括输入验证、错误处理以及安全编程技术的运用。为了获得更高级别的加密保护,可以考虑使用现代加密...
- `csencryptdecrypt.asv`: 这可能是加密解密函数的保存文件,其中包含了加密和解密的具体算法。 - `caesarcipher.fig`: 这是GUI的图形界面文件,可以被MATLAB加载以显示和运行GUI。 - `caesarcipher.m`: 这是MATLAB...
Spring Security 使用数据库认证及用户密码加密和解密功能 Spring Security 是一个基于 Java 的安全框架,提供了强大的身份验证、授权和访问控制功能。为了提高系统安全性,Spring Security 提供了多种身份验证机制...
"凯撒密码的加密和解密" 凯撒密码是一种古典的加密算法,它的加密和解密过程都可以使用C语言来实现。下面我们将对凯撒密码的加密和解密过程进行详细的解释,并对提供的代码进行分析。 凯撒密码的加密过程 凯撒...
通过深入研究并实践这些代码,你可以更好地理解加密解密的工作原理,并为更高级的密码学概念打下坚实的基础。同时,这也提醒我们,尽管这些古典加密方法在现代密码学面前显得较为脆弱,但它们仍然是信息安全领域的...
"密码学DES算法的实现 含有加密和解密" 密码学中的DES算法是对称加密算法的一种,该算法使用C++语言编写,具有加密和解密两个功能。DES算法是美国国家标准局(NBS)于1977年颁布的数据加密标准(FIPS),它使用56位...
使用js对密码加密解密三种方式,包括md5、base64、sha1等主流加密方式。
密码加密和密码解密!! 把用户和密码绑在一起加密,解密也需要用户和加密的密码。
C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与解密C++密码加密与...
该程序是一个简单的密码管理器,使用Java实现,使用Swing作为图形用户界面,它允许用户使用主密码加密和解密密码,密
"对密码进行加密解密" 在本篇文章中,我们将讨论如何实现对登录密码的加密解密,以确保项目安全。为了实现这一点,我们将使用 Java 语言和 DES 加密算法来实现密码的加密和解密。 首先,我们需要了解什么是 DES ...
仿射密码加密与解密C++源程序 仿射密码是一种简单的加密算法,它使用线性变换来进行加密和解密。下面我们将详细介绍仿射密码的加密和解密算法,并提供相应的C++源代码。 仿射密码的加密算法是一个线性算法,密钥...
- 可以编写一个简单的C#程序,使用AES或RSA进行加密解密,展示如何生成密钥、执行加密和解密操作,以及如何处理哈希和盐值。 以上就是C#中密码加密和解密程序所涉及的关键知识点。理解并熟练应用这些概念和方法,...
本示例"DESEncrypt"提供了密码加密和解密的源码,旨在帮助开发者了解并实施安全的密码存储策略。DES(Data Encryption Standard)是一种古老的对称加密算法,虽然现在已经被更先进的AES(Advanced Encryption ...
在标题提到的"rdp文件中的密码加密解密程序"是一种工具,专门设计用来处理RDP文件中的密码加密和解密。当RDP文件中包含`username:s:xxxx`和`password 51:b:xxxxx`这样的条目时,`xxxxx`部分就是经过加密的密码。这个...
总结,Navicat的密码加密和解密涉及到数据安全和个人隐私,理解这一过程有助于更好地管理和保护自己的数据库连接信息。在进行解密操作时,务必注意安全,遵循最佳实践,以确保数据的完整性与隐私。