Skip to content

Commit

Permalink
Assign a random password to an incoming post if none is given
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Merrell committed Nov 5, 2018
1 parent d6be485 commit a865840
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,14 @@ func makePost(writer http.ResponseWriter, request *http.Request) {
return
}
post.MessageHTML = formatMessage(post.MessageText)
post.Password = md5Sum(request.FormValue("postpassword"))
password := request.FormValue("postpassword")
if password == "" {
rand.Shuffle(len(chars), func(i, j int) {
password += fmt.Sprintf("%c", chars[j])
})
password = password[:8]
}
post.Password = md5Sum(password)

// Reverse escapes
nameCookie = strings.Replace(formName, "&", "&", -1)
Expand All @@ -332,7 +339,7 @@ func makePost(writer http.ResponseWriter, request *http.Request) {

// add name and email cookies that will expire in a year (31536000 seconds)
http.SetCookie(writer, &http.Cookie{Name: "name", Value: nameCookie, Path: "/", Domain: domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(yearInSeconds))), MaxAge: yearInSeconds})
http.SetCookie(writer, &http.Cookie{Name: "password", Value: request.FormValue("postpassword"), Path: "/", Domain: domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(yearInSeconds))), MaxAge: yearInSeconds})
http.SetCookie(writer, &http.Cookie{Name: "password", Value: password, Path: "/", Domain: domain, RawExpires: getSpecificSQLDateTime(time.Now().Add(time.Duration(yearInSeconds))), MaxAge: yearInSeconds})

post.IP = getRealIP(request)
post.Timestamp = time.Now()
Expand Down

0 comments on commit a865840

Please sign in to comment.