moezbhatti / qksms

The most beautiful SMS messenger for Android
https://qklabs.com/download
GNU General Public License v3.0
4.47k stars 1.06k forks source link

Copy 2FA code from notification #881

Open moezbhatti opened 6 years ago

moezbhatti commented 6 years ago

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

CometDog commented 6 years ago

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:

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

moezbhatti commented 6 years ago

@PiwwowPants thanks for sharing this!

sm4rk0 commented 5 years ago

This is a great feature!

There's an Xposed module with this functionality, but

I have two suggestions:

maples3 commented 5 years ago

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
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
arn-all commented 4 years ago

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.

chilliger commented 4 years ago

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

chilliger commented 4 years ago

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?

HorlogeSkynet commented 3 years ago

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.