3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-24 19:52:35 +01:00
ergo/irc/migrations/legacy.go

21 lines
838 B
Go
Raw Normal View History

2020-10-02 22:48:37 +02:00
package migrations
import (
"golang.org/x/crypto/bcrypt"
)
// See the v12-to-v13 schema change. The format of this hash is:
// 30 bytes of global salt, 30 bytes of per-passphrase salt, then the bcrypt hash
func CheckOragonoPassphraseV0(hash, passphrase []byte) error {
globalSalt := hash[:30]
passphraseSalt := hash[30:60]
bcryptHash := hash[60:]
assembledPasswordBytes := make([]byte, 0, 60+len(passphrase)+2)
assembledPasswordBytes = append(assembledPasswordBytes, globalSalt...)
assembledPasswordBytes = append(assembledPasswordBytes, '-')
assembledPasswordBytes = append(assembledPasswordBytes, passphraseSalt...)
assembledPasswordBytes = append(assembledPasswordBytes, '-')
assembledPasswordBytes = append(assembledPasswordBytes, passphrase...)
return bcrypt.CompareHashAndPassword(bcryptHash, assembledPasswordBytes)
}