Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 13
- Log:
Initial import of Typo 2.6.0 sources from a downloaded Tarball.
Typo is a Ruby On Rails based blog engine.
- Author:
- adh
- Date:
- Sat Jul 22 22:25:02 +0100 2006
- Size:
- 1857 Bytes
1 | require 'digest/sha1' |
2 | |
3 | # this model expects a certain database layout and its based on the name/login pattern. |
4 | class User < ActiveRecord::Base |
5 | |
6 | # echo "typo" | sha1sum - |
7 | @@salt = '20ac4d290c2293702c64b3b287ae5ea79b26a5c1' |
8 | cattr_accessor :salt |
9 | |
10 | # Authenticate a user. |
11 | # |
12 | # Example: |
13 | # @user = User.authenticate('bob', 'bobpass') |
14 | # |
15 | def self.authenticate(login, pass) |
16 | find_first(["login = ? AND password = ?", login, sha1(pass)]) |
17 | end |
18 | |
19 | def self.authenticate?(login, pass) |
20 | user = self.authenticate(login, pass) |
21 | return false if user.nil? |
22 | return true if user.login == login |
23 | |
24 | false |
25 | end |
26 | |
27 | protected |
28 | |
29 | # Apply SHA1 encryption to the supplied password. |
30 | # We will additionally surround the password with a salt |
31 | # for additional security. |
32 | def self.sha1(pass) |
33 | Digest::SHA1.hexdigest("#{salt}--#{pass}--") |
34 | end |
35 | |
36 | before_create :crypt_password |
37 | |
38 | # Before saving the record to database we will crypt the password |
39 | # using SHA1. |
40 | # We never store the actual password in the DB. |
41 | def crypt_password |
42 | write_attribute "password", self.class.sha1(password) |
43 | end |
44 | |
45 | before_update :crypt_unless_empty |
46 | |
47 | # If the record is updated we will check if the password is empty. |
48 | # If its empty we assume that the user didn't want to change his |
49 | # password and just reset it to the old value. |
50 | def crypt_unless_empty |
51 | if password.empty? |
52 | user = self.class.find(self.id) |
53 | self.password = user.password |
54 | else |
55 | write_attribute "password", self.class.sha1(password) |
56 | end |
57 | end |
58 | |
59 | validates_uniqueness_of :login, :on => :create |
60 | validates_length_of :password, :within => 5..40, :on => :create |
61 | validates_presence_of :login |
62 | |
63 | validates_confirmation_of :password, :if=> Proc.new { |u| u.password.size > 0} |
64 | validates_length_of :login, :within => 3..40 |
65 | end |