3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 02:32:39 +01:00
ergo/irc/migrations/legacy.go
2020-10-02 16:48:37 -04:00

21 lines
838 B
Go

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)
}