Browse Source

Custom password hashing for migrating data

development
Godwin 11 years ago
parent
commit
7a768068ec
  1. 13
      app/assets/stylesheets/sass/_base.scss
  2. 6
      app/assets/stylesheets/sass/_layout.scss
  3. 4
      app/controllers/pages_controller.rb
  4. 6
      app/views/pages/translation_list.html.haml
  5. 1636835
      config/bike_bike.yml
  6. 118
      config/initializers/drupal_hash.rb
  7. 4
      config/initializers/sorcery.rb
  8. 3
      config/locales/pluralization-rules.yml

13
app/assets/stylesheets/sass/_base.scss

@ -48,6 +48,10 @@ table#translations {
} }
.grid.links { .grid.links {
&.inactive li > a {
opacity: 0.75;
}
li > a { li > a {
display: block; display: block;
background-color: $color-5; background-color: $color-5;
@ -55,8 +59,17 @@ table#translations {
padding: 1em; padding: 1em;
min-height: 7em; min-height: 7em;
&.complete {
background-color: $color-2;
}
&.needs-work {
background-color: $color-4;
}
&:hover { &:hover {
background-color: $color-1; background-color: $color-1;
opacity: 1;
} }
h3 { h3 {

6
app/assets/stylesheets/sass/_layout.scss

@ -389,3 +389,9 @@ table {
} }
} }
} }
@media #{$medium-up} {
.top-bar-section li a:not(.button) {
background: transparent !important;
}
}

4
app/controllers/pages_controller.rb

@ -6,9 +6,6 @@ include ApplicationHelper
class PagesController < ApplicationController class PagesController < ApplicationController
def home def home
#password = ""
#hash = ""
#@testResult = RubyDrupalHash::verify(password, hash)
end end
def translate def translate
@ -91,4 +88,5 @@ class PagesController < ApplicationController
end end
I18n.backend.reload! I18n.backend.reload!
end end
end end

6
app/views/pages/translation_list.html.haml

@ -7,10 +7,10 @@
- @language_codes.each do |code| - @language_codes.each do |code|
- if code && @completeness.has_key?(code.to_s) - if code && @completeness.has_key?(code.to_s)
%li.text-center %li.text-center
%a{:href => "/translations/#{code}/"}
%h3=_"languages.#{code}"
- completeness = @completeness[code.to_s] - completeness = @completeness[code.to_s]
- percent = @total_translations ? ((completeness / @total_translations.to_f) * 100).round() : 0 - percent = @total_translations ? ((completeness / @total_translations.to_f) * 100).to_i : 0
%a{:href => "/translations/#{code}/", :class => (percent > 99 ? 'complete' : percent > 67 ? 'needs-work' : nil)}
%h3=_"languages.#{code}"
.completeness .completeness
= "#{completeness} / #{@total_translations} (#{percent}%)" = "#{completeness} / #{@total_translations} (#{percent}%)"
%h2= _ 'languages.inactive' %h2= _ 'languages.inactive'

1636835
config/bike_bike.yml

File diff suppressed because one or more lines are too long

118
config/initializers/drupal_hash.rb

@ -0,0 +1,118 @@
#require 'sorcery/lib/sorcery/crypto_providers/common'
#require 'ruby_drupal_hash'
module Sorcery
module CryptoProviders
class DrupalPassword # < Sorcery::CryptoProviders::Common
include Common
class << self
#def join_token
# @join_token ||= "--"
#end
# Turns your raw password into a Sha1 hash.
def encrypt(*tokens)
#puts tokens
#x
#tokens = tokens.flatten
#digest = tokens.shift
#stretches.times { digest = secure_digest([digest, *tokens].join(join_token)) }
#digest
hash(tokens.first())
end
#def secure_digest(digest)
# #Digest::SHA1.hexdigest(digest)
# hash(digest)
#end
DRUPAL_MIN_HASH_COUNT = 7
DRUPAL_MAX_HASH_COUNT = 30
DRUPAL_HASH_LENGTH = 55
ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
HASH = Digest::SHA2.new(512)
def hash(password)
return false if password.nil?
setting = '$S$DXHwLLD9k'
count_log2 = ITOA64.index(setting[3])
if count_log2 < DRUPAL_MIN_HASH_COUNT or count_log2 > DRUPAL_MAX_HASH_COUNT
return false
end
salt = setting[4..4+7]
if salt.length != 8
return false
end
count = 2 ** count_log2
pass_hash = HASH.digest(salt + password)
1.upto(count) do |i|
pass_hash = HASH.digest(pass_hash + password)
end
hash_length = pass_hash.length
output = setting + _password_base64_encode(pass_hash, hash_length)
if output.length != 98
return false
end
return output[0..(DRUPAL_HASH_LENGTH - 1)]
end
def _password_base64_encode(to_encode, count)
output = ''
i = 0
while true
value = (to_encode[i]).ord
i += 1
output = output + ITOA64[value & 0x3f]
if i < count
value |= (to_encode[i].ord) << 8
end
output = output + ITOA64[(value >> 6) & 0x3f]
if i >= count
break
end
i += 1
if i < count
value |= (to_encode[i].ord) << 16
end
output = output + ITOA64[(value >> 12) & 0x3f]
if i >= count
break
end
i += 1
output = output + ITOA64[(value >> 18) & 0x3f]
if i >= count
break
end
end
puts "\nHASH:\t#{output}\n"
return output
end
end
end
end
end

4
config/initializers/sorcery.rb

@ -203,13 +203,13 @@ Rails.application.config.sorcery.configure do |config|
# use an external encryption class. # use an external encryption class.
# Default: `nil` # Default: `nil`
# #
# user.custom_encryption_provider = user.custom_encryption_provider = Sorcery::CryptoProviders::DrupalPassword
# encryption algorithm name. See 'encryption_algorithm=' for available options. # encryption algorithm name. See 'encryption_algorithm=' for available options.
# Default: `:bcrypt` # Default: `:bcrypt`
# #
user.encryption_algorithm = :sha512 user.encryption_algorithm = :custom#:sha512
# make this configuration inheritable for subclasses. Useful for ActiveRecord's STI. # make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.

3
config/locales/pluralization-rules.yml

@ -129,9 +129,6 @@ is:
it: it:
- one - one
- other - other
iw:
- one
- other
ja: ja:
- other - other
jv: jv:

Loading…
Cancel
Save