1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-31 18:31:01 +00:00

refactor(crypto): use rand.Text() instead of a custom implementation

Go 1.24 provides the helpful rand.Text() function, returning a base32-encoded
string containing at least 128 bits of randomness. We should make use of it
everywhere it makes sense to do so, if only to not having to think about much
entropy do we need for each cases, and just trust the go crypto team.

Also, rand.Read() can't fail, so no need to check its return value:
https://pkg.go.dev/crypto/rand#Read This behaviour is consistent with go's
standard library itself.
This commit is contained in:
jvoisin 2025-06-18 16:12:39 +02:00 committed by Frédéric Guillot
parent 43546976d2
commit 9a1d9593b3
3 changed files with 8 additions and 17 deletions

View file

@ -4,10 +4,10 @@
package storage // import "miniflux.app/v2/internal/storage"
import (
"crypto/rand"
"database/sql"
"fmt"
"miniflux.app/v2/internal/crypto"
"miniflux.app/v2/internal/model"
)
@ -56,7 +56,7 @@ func (s *Storage) UserSessions(userID int64) (model.UserSessions, error) {
// CreateUserSessionFromUsername creates a new user session.
func (s *Storage) CreateUserSessionFromUsername(username, userAgent, ip string) (sessionID string, userID int64, err error) {
token := crypto.GenerateRandomString(64)
token := rand.Text()
tx, err := s.db.Begin()
if err != nil {