Feat: use hash version

pull/21/head
zijiren233 2 years ago
parent 0af8b6b6d5
commit e697e09050

@ -2,6 +2,7 @@ package op
import (
"errors"
"hash/crc32"
"net/url"
"sync/atomic"
"time"
@ -298,7 +299,7 @@ func (r *Room) SetPassword(password string) error {
if err != nil {
return err
}
atomic.AddUint32(&r.version, 1)
atomic.StoreUint32(&r.version, crc32.ChecksumIEEE(hashedPassword))
}
r.HashedPassword = hashedPassword
return db.SetRoomHashedPassword(r.ID, hashedPassword)

@ -2,7 +2,7 @@ package op
import (
"errors"
"math/rand"
"hash/crc32"
"sync/atomic"
"github.com/synctv-org/synctv/internal/db"
@ -31,7 +31,7 @@ func WithVersion(version uint32) RoomConf {
func initRoom(room *model.Room, conf ...RoomConf) (*Room, error) {
r := &Room{
Room: *room,
version: rand.Uint32(),
version: crc32.ChecksumIEEE(room.HashedPassword),
current: newCurrent(),
}
for _, c := range conf {

@ -2,6 +2,7 @@ package op
import (
"errors"
"hash/crc32"
"sync/atomic"
"github.com/synctv-org/synctv/internal/db"
@ -62,6 +63,7 @@ func (u *User) SetPassword(password string) error {
}
}
u.HashedPassword = hashedPassword
atomic.AddUint32(&u.version, 1)
atomic.StoreUint32(&u.version, crc32.ChecksumIEEE(u.HashedPassword))
return db.SetUserHashedPassword(u.ID, hashedPassword)
}

@ -1,6 +1,7 @@
package op
import (
"hash/crc32"
"time"
"github.com/bluele/gcache"
@ -26,7 +27,7 @@ func GetUserById(id uint) (*User, error) {
u2 := &User{
User: *u,
version: 1,
version: crc32.ChecksumIEEE(u.HashedPassword),
}
return u2, userCache.SetWithExpire(id, u2, time.Hour)
@ -64,7 +65,7 @@ func CreateUser(username, password string) (*User, error) {
u2 := &User{
User: *u,
version: 1,
version: crc32.ChecksumIEEE(u.HashedPassword),
}
return u2, userCache.SetWithExpire(u.ID, u2, time.Hour)

Loading…
Cancel
Save