Пример #1
0
func Crypt(key, salt string) string {
	ckey := C.CString(key)
	csalt := C.CString(salt)
	crypt_m.Lock()
	out := C.GoString(C.crypt(ckey, csalt))
	crypt_m.Unlock()
	C.free(unsafe.Pointer(ckey))
	C.free(unsafe.Pointer(csalt))
	return out
}
Пример #2
0
func Crypt(key, slash string) (digest string, err error) {
	if len(slash) != 2 {
		err = errors.New("Slash invalid.")
		return
	}
	k, s := C.CString(key), C.CString(slash)
	defer func() {
		C.free(unsafe.Pointer(k))
		C.free(unsafe.Pointer(s))
	}()
	d, err := C.crypt(k, s)
	if err != nil {
		return
	}
	digest = C.GoString(d)
	return
}
Пример #3
0
Файл: util.go Проект: cooee/FTP
func AuthPasswd(name string, passwd string) bool {
	nameC := C.CString(name)
	defer C.free(unsafe.Pointer(nameC))

	passwdC := C.CString(passwd)
	defer C.free(unsafe.Pointer(passwdC))

	pwd := C.getspnam(nameC)
	if pwd == nil {
		return false
	}
	crypted := C.crypt(passwdC, pwd.sp_pwdp)
	rv := C.strcmp(crypted, pwd.sp_pwdp)
	if rv != 0 {
		return false
	}

	return true
}
func generateSha512(password string) string {
	shadowRecord := fmt.Sprintf("$6$%s", generateShaSalt())
	return C.GoString(C.crypt(C.CString(password), C.CString(shadowRecord)))
}