Storing # as password in .env file

Viewed 5347

My current server password is a123!@#ASD but in .env file # is used to comment out something. So characters after # in my password are neglected and I can't connect to my server. Is there any escaping way in .env file so that I can use my current password.

3 Answers

As per Laravel Documenation

All variables in your .env files are parsed as strings

If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes.

"Laravel" treats # as comment. So if there is space or # in your password then you have to enclosed it in double quotes("")

  DB_PASSWORD =  "a123!@#ASD"

https://laravel.com/docs/6.x/configuration

In a scenario I have something like this with json in .env:

#Parsed by skiping after #: '[{"name":"dummy1",password:"Pass'
destinations=[{"name":"dummy1",password:"Pass#1234"];

#parsed to correct string : '[{"name":"dummy1",password:"Pass#1234"]'
destinations=`[{"name":"dummy1",password:"Pass#1234"]`;

Ref: dotenv vesrion: 16.0.1 https://www.npmjs.com/package/dotenv

backticks are supported (BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.`)

Related