fake_password_field 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f522d8c3abe3cb5917c5389bbbbbd93996ff79b
4
- data.tar.gz: 15b4cb332717b8143100eb7f1c99513ef751adb1
3
+ metadata.gz: 1f0e7ed13d10911f2f14a31138b793471ae163df
4
+ data.tar.gz: 8583916fb7ae6cf62acb051b24c809573ec00a69
5
5
  SHA512:
6
- metadata.gz: 193d2226ddca4262369530ef3f75999d77a942a985bb58ad572ed5284735834a5159214d71910bb90d61f13618d9f536a152f73214eeadb324ae7985828f3a19
7
- data.tar.gz: 90f542030942c95709b35cc9f0cf54cce38bbfe8fcfe0ba3a466a21f9794b6e14a0915887f727f4fe8c9d9506ba7a597d559c2b2fce8c89a9bed149016f1c616
6
+ metadata.gz: b96fa92fcbf425d42e16a9cdfb49f39570a116b5ea1caf11b19736acf097744247bce792ad4214a2dd480bba943909440ece2e3239f163fbff17fa69c9b9f6b0
7
+ data.tar.gz: dd0fc7d8598c60cdf8a799fbce4cd1839df5b3b075a849f2db0856fbfbb798aeca38a9b6a86768b700ff358aad65d1aa936104d1607e7efe505b0d215e003bc1
data/README.md CHANGED
@@ -22,24 +22,16 @@ Available on RubyGems: https://rubygems.org/gems/fake_password_field
22
22
 
23
23
  ### Usage
24
24
 
25
- In your views, replace `password_field_tag` with `fake_password_field_tag`. Or if you're using a FormBuilder (`form_for(@object)...`), replace `f.password_field` with `f.fake_password_field`.
26
-
27
- All other parameters should be the same - you shouldn't need to change anything else in your view code. Please create an issue if that isn't the case.
25
+ Add a `fake_password_field_tag` to the top of your page. Or if you're using a FormBuilder (`form_for(@object)...`), add a `f.fake_password_field`.
28
26
 
29
27
  ### How it works
30
28
 
31
- The gem will render a text field (`<input type=text>`) with the same markup as your password field. Directly below, it inserts a snippet of Javascript that will convert this text field to a password field after the page has loaded and Safari's autofiller has finished running.
32
-
33
- The snippet looks like this:
29
+ This inserts a dummy HTML password element, which is hidden from view and will not be posted. But it will trick Safari into not autofilling your actual password field.
34
30
 
35
- ````javascript
36
- <script>
37
- // http://stackoverflow.com/q/22817801/641293
38
- var i = document.getElementsByTagName('input'), e = i[i.length - 1]
39
- setTimeout(function() { e.type = 'password' }, 500)
40
- </script>
41
- ````
31
+ You should experiment with the best place in the form to add this element. Usually adding it to the top works well, but some form layouts work best if it's added to the bottom.
42
32
 
43
- ### Shortfalls
33
+ The HTML looks like this:
44
34
 
45
- If you have a default value in the password field, that value will flash briefly before being replaced by the password field dots. Generally it's not considered a good practice to include the user's password (or indeed, any password) in your HTML. But if you really need to, you should try one of the other workarounds suggested at http://stackoverflow.com/questions/22817801/how-to-disable-auto-fill-in-safari-7 or elsewhere, instead of this gem.
35
+ ````html
36
+ <div class="break_safari_autofill" style="left: -9999px; position: fixed; width: 1px;"><input type="password"></div> <!-- http://stackoverflow.com/a/24471266/641293 -->
37
+ ````
@@ -1,16 +1,11 @@
1
1
  module ActionView
2
2
  module Helpers
3
3
  class FormBuilder
4
- def fake_password_field(method, options = {})
5
- text_field_output = text_field(method, options)
6
- javascript = <<-STR
7
- <script>
8
- // http://stackoverflow.com/q/22817801/641293
9
- var i = document.getElementsByTagName('input'), e = i[i.length - 1]
10
- setTimeout(function() { e.type = 'password' }, 500)
11
- </script>
4
+ def fake_password_field
5
+ html = <<-STR
6
+ <div class="break_safari_autofill" style="left: -9999px; position: fixed; width: 1px;"><input type="password"></div> <!-- http://stackoverflow.com/a/24471266/641293 -->
12
7
  STR
13
- "#{text_field_output} #{javascript}".html_safe
8
+ html.html_safe
14
9
  end
15
10
  end
16
11
  end
@@ -19,16 +14,11 @@ end
19
14
  module ActionView
20
15
  module Helpers
21
16
  module FormTagHelper
22
- def fake_password_field_tag(name = "password", value = nil, options = {})
23
- text_field_output = text_field_tag(name, value, options)
24
- javascript = <<-STR
25
- <script>
26
- // http://stackoverflow.com/q/22817801/641293
27
- var i = document.getElementsByTagName('input'), e = i[i.length - 1]
28
- setTimeout(function() { e.type = 'password' }, 500)
29
- </script>
17
+ def fake_password_field_tag
18
+ html = <<-STR
19
+ <div class="break_safari_autofill" style="left: -9999px; position: fixed; width: 1px;"><input type="password"></div> <!-- http://stackoverflow.com/a/24471266/641293 -->
30
20
  STR
31
- "#{text_field_output} #{javascript}".html_safe
21
+ html.html_safe
32
22
  end
33
23
  end
34
24
  end
@@ -1,3 +1,3 @@
1
1
  module FakePasswordField
2
- VERSION = 1.1
2
+ VERSION = 1.2
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_password_field
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Ghiculescu