From cb439a126aa6a2728e423bcfd0d5e948337b8ddb Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Tue, 14 Apr 2020 09:41:54 +0800 Subject: db: add tests for two factors (#6099) * Rename to TwoFactors.Create * Use GORM to execute queries * TwoFactor.GetByUserID * Add tests * Fix failing tests * Add MD5 tests * Add tests for RandomChars --- internal/cryptoutil/md5.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/cryptoutil/md5.go (limited to 'internal/cryptoutil/md5.go') diff --git a/internal/cryptoutil/md5.go b/internal/cryptoutil/md5.go new file mode 100644 index 00000000..249f3ed5 --- /dev/null +++ b/internal/cryptoutil/md5.go @@ -0,0 +1,22 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cryptoutil + +import ( + "crypto/md5" + "encoding/hex" +) + +// MD5 encodes string to hexadecimal of MD5 checksum. +func MD5(str string) string { + return hex.EncodeToString(MD5Bytes(str)) +} + +// MD5Bytes encodes string to MD5 checksum. +func MD5Bytes(str string) []byte { + m := md5.New() + _, _ = m.Write([]byte(str)) + return m.Sum(nil) +} -- cgit v1.2.3