Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a new application.secret in Play 2.x

Apparently Play 1.x had a command 'play secret' that would create a new application.secret, but I don't see an equivalent command in Play 2.x. It is recommended to change the key when moving from development to production, so I need to find a way to make a new key for that.

like image 449
egprentice Avatar asked Sep 24 '13 18:09

egprentice


People also ask

How do I run in production mode?

The easiest way to start an application in production mode is to use the start command from the Play console. This requires a Play installation on the server. When you run the start command, Play forks a new JVM and runs the default Netty HTTP server.

How do I run a play Framework project?

To run the tutorial: Unzip the project in a convenient location. In a command window, change to the top-level project directory. Enter sbt run .


2 Answers

You are right. I think this feature is not yet implemented in 2.x version. I am afraid the only way to do is to create a new project. Each new project will generate a new secret key. And then copy only the newly generated key.

I think this issue was raised for your problem: https://github.com/n8han/giter8/issues/42 referenced in https://groups.google.com/forum/#!topic/play-framework/aMyM_fDglSs

Good luck.

EDIT 2020-01-23:

It would appear that they went back to camel-case, so on current versions of Play w/ SBT it should be

sbt playGenerateSecret

EDIT 2015-05-11:

As noted by @myk this is now implemented in the sbt plugin, you need to run:

sbt play-generate-secret

or

sbt play-update-secret

Edit 2015-07-02

Using activator:

activator playGenerateSecret
like image 71
adis Avatar answered Dec 11 '22 09:12

adis


This is how you can do it in Scala console:

$ scala

scala> val r = new java.security.SecureRandom
r: java.security.SecureRandom = java.security.SecureRandom@b4ca6f6

scala> (1 to 64).map(_=>(r.nextInt(74)+48).toChar).mkString.replaceAll("\\\\+", "/")
res4: String = cCU`liU?i^R3f:Tk3ekG9a0^hjtwADUi@X2OtjAqKG`vv/>dk@cq_QOnu47WQ<0_

Your secret is key now is:

cCU`liU?i^R3f:Tk3ekG9a0^hjtwADUi@X2OtjAqKG`vv/>dk@cq_QOnu47WQ<0_
like image 43
tuxdna Avatar answered Dec 11 '22 10:12

tuxdna