Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to generate 4 digit code? #12

Closed
shivanibhanwal opened this issue Aug 21, 2014 · 6 comments
Closed

Is there a way to generate 4 digit code? #12

shivanibhanwal opened this issue Aug 21, 2014 · 6 comments

Comments

@shivanibhanwal
Copy link
Contributor

Hi @robertomiranda,
Thank you for the nice gem. It is really helpful for the OTP generation.
I am using it in my project however we have requirement of 4 digit otp code instead of 6 digit.
Would like to know is there a way to customise it to make it 4 digit or any number of digit?

Another question about Padding a otp code. I have seen that one of the issue has been closed and there has been a pull request. However I am using active_model_otp (1.0.0) version in my project. But still I am getting 5 digit digit some times randomly. And also I did not set any "padding: false"

Is that change related to padding has been published ?

Thanks
Shivani

@robertomiranda
Copy link
Member

@shivanibhanwal currently there's not way to specified a length for the code generated, but is something that we can add look https://github.com/mdp/rotp/blob/master/lib/rotp/otp.rb#L14 and would looks like:

class User < ActiveRecord::Base
  has_one_time_password length: 4
end

about your second question, could you paste some code in order to repreduce the issue?. for me is working good

@shivanibhanwal
Copy link
Contributor Author

Thank you @robertomiranda ! yes I think that would really help as most of the time people use 4 or 6 digit code for OTP
I am planning to make this change If I am done soon will send you a PR
(will make change here -

self.otp_column_name = (options[:column_name] || "otp_secret_key").to_s
)

@shivanibhanwal
Copy link
Contributor Author

About the other issue I see code is there in the gem files.
In my case I am not using same User table for the Token. I have separate Auth_tokens table for the token. Also the time drift which we needed that is like few minutes so I have passed drift value.
When I test my app for 1-2 hours after every 10-15 tries I get one OTP which is 5 digit.
And that cause a problem too. when I try to authenticate it it does not authenticate 5 digit otp.

user = self.auth_token
drift_time = Time.now + drift
new_otp = user.otp_code(drift_time)

and this time I got it 3 digit

UPDATE "auth_tokens" SET "otp_code" = 940, "otp_code_expiry" = '2014-08-21 17:11:50.147128' 

Its happening verify frequently

@shivanibhanwal
Copy link
Contributor Author

@robertomiranda About my second query, Issue was the DataType of the "otp_code" field. I was having it as integer and that was trimming these zero paddings.
I have implemented dynamic length for the otp_code. I have not sent a PR as I am yet to write tests for it.
However you can review my changes here https://github.com/shivanibhanwal/active_model_otp/tree/otp_generation_with_custom_length.

@robertomiranda
Copy link
Member

@shivanibhanwal for sure, I'll take a look 👍, but please open the Pull request anyway this can help us to keep and track better the discussion.

@shivanibhanwal
Copy link
Contributor Author

Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants