Qksms: Copy 2FA code from notification

Created on 13 Feb 2018  Â·  8Comments  Â·  Source: moezbhatti/qksms

If a 2FA code is detected in a notification, we should add a notification action for copying the code to the clipboard

feature

Most helpful comment

This is a really cool feature!

The other linked issue (#1101) suggested copying other things too, like phone numbers. I found an online regex tester and poked around for a bit, and came up with this:

([\+\(]?([0-9][ \-\(\)\.]{0,2}){2,})

It matches digits with up to 2 "separator" characters after them, plus some "prefix" characters. Currently, though, it does catch trailing space characters (though you could call .strip() after the regex :) ) It also requires at least two digit/separator characters, to ignore things like the comment in the example.

I'm not super familiar with regular expressions, so feel free to clean it up if it needs it!

Here's some sample input I was testing against:

(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890
G-123456 // Google sends their 2-factor auth codes with a prefix, though they don't want you to type it in
129-324
832737

All 8 comments

It's not the best code I've written, but at one point (and committed recently since I saw this), I wrote this up for myself with QKSMS.
It will show the code if:

  • The message contains the word "code" (since most do that I looked through personally)
  • There is a numeric value from 3-10 digits
  • There are no other numeric values in the message

Failure case: "Zip code is 90210"

It's pretty sloppy so not super merge-able but I figured I would link it here for any sort of observation.
https://github.com/moezbhatti/qksms/compare/master...PiwwowPants:feature/copy-2fa-codes?expand=1

@PiwwowPants thanks for sharing this!

This is a great feature!

There's an Xposed module with this functionality, but

  • it requires Xposed (non-trivial for most users)
  • it includes privacy-intrusive Umeng library

I have two suggestions:

  • Consider "copy-to-clipboard & mark-as-read" notification action.
  • There are a lot of users who receive 2FA messages in their native (non English) language, so the word "code" wouldn't be applicable. One option would be a user-definable list of trigger words and/or a user-contributable (via GitHub) built-in list.

This is a really cool feature!

The other linked issue (#1101) suggested copying other things too, like phone numbers. I found an online regex tester and poked around for a bit, and came up with this:

([\+\(]?([0-9][ \-\(\)\.]{0,2}){2,})

It matches digits with up to 2 "separator" characters after them, plus some "prefix" characters. Currently, though, it does catch trailing space characters (though you could call .strip() after the regex :) ) It also requires at least two digit/separator characters, to ignore things like the comment in the example.

I'm not super familiar with regular expressions, so feel free to clean it up if it needs it!

Here's some sample input I was testing against:

(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890
G-123456 // Google sends their 2-factor auth codes with a prefix, though they don't want you to type it in
129-324
832737

Another point is that some SMS are written with several numbers in it "for you payment of 123,45€ on bank account ending with 1234, use the code 1827391". We also need to be mindful of comma separated number used in some regions, as shown in my example.
Being able to automatically underline any code/phone number/number from a SMS in order to copy any of them could be a nice start in my opinion.

Maybe one of the APIs provided by google could be used in some way: https://proandroiddev.com/new-way-of-sms-retriever-api-sms-user-consent-d7210c00d7c9

I was able to copy the OTP (numeric) through a button provided by the QKSMS notification. I am running LOS17.1. Is this a Android 10 feature?

I was able to copy the OTP (numeric) through a button provided by the QKSMS notification. I am running LOS17.1. Is this a Android 10 feature?

It is.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabkomarnicki picture gabkomarnicki  Â·  4Comments

pkabrahamsen picture pkabrahamsen  Â·  5Comments

phileastv picture phileastv  Â·  4Comments

spocko picture spocko  Â·  3Comments

nosoop picture nosoop  Â·  4Comments