javascriptregexdiscord.jstoken

Is there a way to check if a discord account token is valid or not?


As the title says, I'm trying to create a script that will check if a discord account token (not a bot token) is valid or not. I've tried regex matching like this:

/^(?=\S*[a-z])(?=\S*[A-Z])(?=\S*\d)(?=\S*[^\w\s]\S{5,}$/g.test(token)

but I don't think this is the best method, and I feel like some tokens can slip through the net if I use this sort of detection method to check if they're valid.


Solution

  • The regex for a token with mfa protection is /mfa\.[\w-]{84}/, without mfa protection is /[\w-]{24}\.[\w-]{6}\.[\w-]{27}/.

    Then you can check it using discord api with the token in Authorization header