Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:06:20+00:00 2026-05-21T00:06:20+00:00

We have decided to start work on Multi-factor authentication, by way of releasing an

  • 0

We have decided to start work on Multi-factor authentication, by way of releasing an iPhone, Android and Blackberry app for our customers.

Think Google Authenticator‘s one-time password system.

I can get how I could generate a unique string by hashing using a SALT based on the account secret key plus the device serial number (or other unique identifier).

But does anyone have any idea how you could generate a unique, short number, in the way that google does? And/or does anyone have any good links to articles on achieving this kind of thing?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T00:06:21+00:00Added an answer on May 21, 2026 at 12:06 am

    In the end I found that this was very well documented in RFC 4226 and regarding the integer conversion, this can be done using the bitwise operation shown on page 7, essentially it is the same as that shown in the answer below.

    There was another post on stackoverflow regarding this in a C# context, which may be worth a read if you are in a similar position.

    In C# I basically, hashed a time identifier (i.e. the current time in seconds divided by 30 – to get a long which is valid for the current 30-second interval). Then hashed this using my secret key as the SALT.

    And then…

    // Use a bitwise operation to get a representative binary code from the hash
    // Refer section 5.4 at https://www.rfc-editor.org/rfc/rfc4226#page-7            
    int offset = hashBytes[19] & 0xf;
    int binaryCode = (hashBytes[offset] & 0x7f) << 24
        | (hashBytes[offset + 1] & 0xff) << 16
        | (hashBytes[offset + 2] & 0xff) << 8
        | (hashBytes[offset + 3] & 0xff);
    
    // Generate the OTP using the binary code. As per RFC 4426 [link above] "Implementations MUST extract a 6-digit code at a minimum 
    // and possibly 7 and 8-digit code"
    int otp = binaryCode % (int)Math.Pow(10, 6); // where 6 is the password length
    
    return otp.ToString().PadLeft(6, '0');
    

    For those of you who didn’t know, Google Authenticator is an open source project – you can browse the source code here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I should have taken a branch to start with but decided to work on
I am trying to work my way through basic iPhone programming and I have
I have decided to start using unit testing in PL/SQL, since it could be
I'm new to programming and stackoverflow and have decided to start by learning objective
We have decided to work with the Insert Framework Here We'll most likely update
I have written an Qt application. On Windows 7 x64/x32 app work's fine. On
I've decided to start versioning my project the Apple way, using Bundle versions string,
I have different screen to work in an android application. I'm using ViewFlipper for
I have this function which used to work, but apparently decided to take a
I have a Django application which I decided to port to Google App Engine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.