Jump to content

Find 2Fa/two-factor auth codes in Messages


Recommended Posts

Posted
17 hours ago, forgetfulfellow said:

Is something broken on my side?

 

No. The workflow is really choosy in what it considers a 2fa code. It only matches messages where the word "code" appears before the number, not after.

 

I wonder if it might work better if the workflow were less choosy about what it considers a code, but perhaps more restrictive about how recent the message needs to be? A false positive isn't a huge deal because the workflow isn't inserting and submitting the codes automatically.

  • 3 months later...
Posted
On 2/1/2020 at 3:02 PM, Cheah said:

 

 

Screen-Shot-2020-02-01-at-9-58-13-AM.jpg

Screen-Shot-2020-02-01-at-9-58-26-AM.jpg

 

Not sure what's going on here?

 

I get the same thing - just downloaded the latest version of the workflow.

 

Log shows this -

 

[12:25:23.781] Logging Started...
[12:25:31.242] iMessage 2FA[Script Filter] Queuing argument ''
[12:25:31.312] iMessage 2FA[Script Filter] Script with argv '' finished
[12:25:31.314] ERROR: iMessage 2FA[Script Filter] Code 127: /Users/MVR/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E2E72D95-AC79-413C-849E-619AD2A47E78: line 1: php: command not found

 

 

  • 2 months later...
Posted (edited)

I just released version 1.2.8 of the workflow, which has the following changes:

  • The `php` binary is located on your system to cover situations where it isn't in your `PATH`
    • If the `php` binary can't be found, an error message is displayed
  • Match 4-8 digit codes followed by "is your [...] code". For example: "2773 is your Microsoft account verification code"

Download the latest release: https://github.com/squatto/alfred-imessage-2fa/releases/download/v1.2.8/iMessage.2FA.alfredworkflow

Edited by squatto
Typo
Posted
On 8/30/2021 at 5:57 AM, deanishe said:

Your OS is unsupported. Apple has removed PHP from macOS.

 

While it is true that Apple has removed PHP from macOS, it's a very simple process to install it again:

  1. Install Homebrew by following the installation instructions on the Homebrew website
  2. Install `php`:
brew install php

 

The latest version of the workflow (v1.2.8) will automatically locate and use the correct `php` binary on your system.

Posted
On 5/28/2021 at 3:08 AM, deanishe said:

No. The workflow is really choosy in what it considers a 2fa code. It only matches messages where the word "code" appears before the number, not after.

 

There's actually a number of different formats that it looks for. Here's the relevant code from the latest version (you can also view it on GitHub here). The comments tell you what it's looking for and has example messages.

 

if (preg_match('/(^|\s|\R|\t|\b|G-|:)(\d{5,8})($|\s|\R|\t|\b|\.|,)/', $text, $matches)) {
    // 5-8 consecutive digits
    // examples:
    //   "您的验证码是 199035,10分钟内有效,请勿泄露"
    //   "登录验证码:627823,您正在尝试【登录】,10分钟内有效"
    //   "【赛验】验证码 54538"
    //   "Enter this code to log in:59678."
    //   "G-315643 is your Google verification code"
    //   "Enter the code 765432, and then click the button to log in."
    //   "Your code is 45678!"
    //   "Your code is:98765!"
    $code = $matches[2];
} elseif (preg_match('/^(\d{4,8})(\sis your.*code)/', $text, $matches)) {
    // 4-8 digits followed by "is your [...] code"
    // examples:
    //   "2773 is your Microsoft account verification code"
    $code = $matches[1];
} elseif (preg_match('/(code:|is:)\s*(\d{4,8})($|\s|\R|\t|\b|\.|,)/i', $text, $matches)) {
    // "code:" OR "is:", optional whitespace, then 4-8 consecutive digits
    // examples:
    //   "Your Airbnb verification code is: 1234."
    //   "Your verification code is: 1234, use it to log in"
    //   "Here is your authorization code:9384"
    $code = $matches[2];
} elseif (preg_match('/(code|is):?\s*(\d{3,8})($|\s|\R|\t|\b|\.|,)/i', $text, $matches)) {
    // "code" OR "is" followed by an optional ":" + optional whitespace, then 3-8 consecutive digits
    // examples:
    //   "Please enter code 548 on Zocdoc."
    $code = $matches[2];
} elseif (preg_match('/(^|code:|is:|\b)\s*(\d{3})-(\d{3})($|\s|\R|\t|\b|\.|,)/', $text, $matches)) {
    // line beginning OR "code:" OR "is:" OR word boundary, optional whitespace, 3 consecutive digits, a hyphen, then 3 consecutive digits
    // but NOT a phone number (###-###-####)
    // examples:
    //   "123-456"
    //   "Your Stripe verification code is: 719-839."
    $first = $matches[2];
    $second = $matches[3];

    // make sure it isn't a phone number
    // doesn't match: <first digits>-<second digits>-<4 consecutive digits>
    if (! preg_match('/(^|code:|is:|\b)\s*' . $first . '-' . $second . '-(\d{4})($|\s|\R|\t|\b|\.|,)/', $text, $matches)) {
        $code = $first . $second;
    }
}

 

I've added new formats and changed existing formats at the request of users of the workflow. You can submit an issue on the GitHub repo if you have a suggestion!

 

On 5/28/2021 at 3:08 AM, deanishe said:

I wonder if it might work better if the workflow were less choosy about what it considers a code, but perhaps more restrictive about how recent the message needs to be? A false positive isn't a huge deal because the workflow isn't inserting and submitting the codes automatically.

 

You can change the number of minutes it looks back by going into the workflow variables. Here is a screenshot showing you how to do it:

 

workflow-variables.png.358bc7f33cd427177be28d311cb51632.png

Posted

The regexes are getting pretty hairy now. I wonder if it might not be more manageable to split identification of code messages (i.e. check for words like "code", "2FA" etc.) from the actual extraction of the codes?

Posted
On 11/5/2021 at 8:42 PM, squatto said:

I just released version 1.2.8 of the workflow, which has the following changes:

  • The `php` binary is located on your system to cover situations where it isn't in your `PATH`
    • If the `php` binary can't be found, an error message is displayed
  • Match 4-8 digit codes followed by "is your [...] code". For example: "2773 is your Microsoft account verification code"

Download the latest release: https://github.com/squatto/alfred-imessage-2fa/releases/download/v1.2.8/iMessage.2FA.alfredworkflow

Hey squatto, for some reason I get this error when trying to run the workflow:

[19:24:42.861] iMessage 2FA[Script Filter] {"items":[{"arg":"","subtitle":"We were unable to run the query that reads your text messages","title":"ERROR: Unable to Query Your Messages","valid":true},{"arg":"","subtitle":"SQLSTATE[HY000]: General error: 14 unable to open database file","title":"Error Message:","valid":true}]}

 

Posted

I get the error 'unable to access the file that contains your text messages' 

this is mac book pro .. just updated to monterey . install brew .. installed php .. 

 

 

Screen Shot 2021-11-14 at 10.47.31 AM.png

  • 4 weeks later...
Posted (edited)
2 hours ago, squatto said:

 

You need to grant full disk access to Alfred. You can find instructions here: https://www.alfredapp.com/help/getting-started/permissions/#full-disk

 

Let me know if that doesn't fix it for you!

I already done that, but it dosen't work... I also tried uninstalling Alfred and removing all permissions, installing Alfred again and grant permissions but it does not seam to work 😕 
That's why i thought there could be some permissions i need to grant or terminale lines i needed to run 😊 

 

Heres what Alfred says when trying to debug with 2 warnings:

-----------------------------------------------------------

Check file cache database...

File cache integrity is ok

-----------------------------------------------------------

Check if file is readable...

Alfred has permissions to read this file.

-----------------------------------------------------------

Check if volume '/' is indexed by macOS...

Indexing is enabled on this drive

-----------------------------------------------------------

Check direct file metadata...

⚠️ Direct metadata available, but content type may be incorrect

Display Name: chat.db
 Other Names: 
Content Type: dyn.ah62d4rv4ge80k2u
   Last Used: 2021-12-02 12:34:16 +0000

-----------------------------------------------------------

Check mdls file metadata...

Metadata contains required items

-----------------------------------------------------------

Check file is in search scope...

⚠️ File isn't within Alfred's default search scope

Add relevant folder to Alfred's Default Search Scope, or if you're using a workflow, add to the File Filter's scope

-----------------------------------------------------------

Troubleshooting passed

⚠️ There were 2 warning(s)
 

Edited by Slazh
Posted

Hi, great idea, I often miss the function of inserting codes too, but I have a problem with this workflow, error as in the screenshot, how to fix it? All the permissions I have given to alfred, I don’t understand what’s wrong


688168006_CleanShot2021-12-14at00_53.19@2x.thumb.png.c58427c52cf2c7f20605589c75b806bb.png

  • 3 weeks later...
  • 11 months later...
Posted (edited)

Not sure what happened now. It was working fine until recently

 

It launches fine with "2fm" - it finds the code - I selct and press enter - Alfred notification says code was copied.

 

But when I go to paste - it's not there.  Whatever was previously copied is pasted

 

Alfred 5.06

2fm ver 1.2.8

MacOS 13.1

Edited by MVR London
added version numbers
Posted

Love this workflow, been using it for years now. Was wondering, Is it possible to trigger this with a shortcut and have it select the most recent one, then paste it? i.e. Avoiding the Alfred UI altogether? Cheers/Thanks.

  • 1 year later...
Posted

Hello! Love this workflow. Would it be possible to add the capability to delete the selected message? 

 

Thanks! 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...