Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mushood's avatar
Level 41

Special Characters In Password

Hello

I am working on a project where I generate a password for a user and include some special characters in the user's password.

The characters are: '#_%*+=-' (excluding the quotes)

I then send the user this password in an HTML email.

The weird behavior: A few times, when the user enters the password, it does not work. Most of the times, it works just fine.

Things i have tried:

  1. Created a phpunit script to test the whole flow. I saved the generated password in plain in the db and use it to make my login request. Tested for over 15k users, works just fine

  2. Tested manually several times. Reproduced the error once. The password hash was different from the plain password. The issue here was the use of the ^ special character.

Leads:

  1. The HTML rendering is wrong in the email. However, the special characters used should not cause this.

  2. The user is making a mistake when copy/pasting

Any thoughts?

0 likes
4 replies
uju's avatar
uju
Best Answer
Level 24

Is it a text or markdown email template? If it's markdown you will need to escape a lot of special characters.

Snapey's avatar

Just remember "length beats complexity"

don't be afraid to reduce the character set, just compensate with more length.

(you are sending passwords by email, so you can't be that concerned about security)

1 like

Please or to participate in this conversation.