Skip to content

Commit

Permalink
ensure 2 digit sets in string to hex conversion fixing Google 2FA issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Oct 21, 2014
1 parent d3f980f commit 7df9e02
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ Base32 decoding

| Version | Notes |
|:-----------|:------------|
| 1.1.2 | Bug in string to hex conversion resulting in failed Google Apps Code Generation|
| 1.1.1 | Bug in decoding (uppercase) resulting in unsync tokens + jshint fixes|
| 1.1.0 | Added check function to core and readme change |
| 1.0.0 | Stable Release |
Expand Down
2 changes: 1 addition & 1 deletion lib/components/googleAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var googleAuthenticator = {

// Base32 encoding
encode: function encode(secret) {
return base32.encode(secret).toUpperCase();
return base32.encode(secret).replace(/=/g,'');
},


Expand Down
10 changes: 8 additions & 2 deletions lib/components/otplib.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,16 @@ otplib.prototype.helpers = {

// Converts String to Hex
stringToHex: function stringToHex(value) {
var _hex = '';
var _hex = '',
_tmp = '';

for (var i = 0; i < value.length; i++){
_hex += '' + value.charCodeAt(i).toString(16);

// Convert to Hex and Ensure it's in 2 digit sets
_tmp = ('0000' + value.charCodeAt(i).toString(16)).slice(-2);

// Append
_hex += '' + _tmp;
}

return _hex;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "otplib",
"version": "1.1.1",
"version": "1.1.2",
"main": "lib/index.js",
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
"homepage": "https://github.com/yeojz/otplib",
Expand All @@ -22,7 +22,7 @@
"files": [
""
],
"keywords": ["otp", "totp", "hotp", "one time password", "google authenticator", "authentication"],
"keywords": ["otp", "totp", "hotp", "one time password", "google authenticator", "authentication", "2FA", "2 factor"],
"devDependencies": {
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-nodeunit": "~0.2.0",
Expand Down

0 comments on commit 7df9e02

Please sign in to comment.