HashedPw.cpp revision 128c985cbcd15f78b4f54364533dee56100dd2a9
/* $Id$ */
/** @file
* Main - Password Hashing
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "HashedPw.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* The prefix of a hashed password.
*/
static const char s_szHashedPwPrefix[] = "#SHA-512#";
/**
* Checks if the password is a hashed one or not.
*
* Empty password are not considered hashed.
*
* @returns true if hashed, false if not.
* @param a_pstrPassword Password to inspect.
*/
{
/* prefix */
return false;
/* salt (optional) */
if (!pszSaltEnd)
return false;
while (pszSalt != pszSaltEnd)
{
if (!RT_C_IS_XDIGIT(*pszSalt))
return false;
pszSalt++;
}
/* hash */
return RT_SUCCESS(rc);
}
/**
* Hashes a plain text password.
*
* @param a_pstrPassword Plain text password to hash. This is both
* input and output.
*/
{
if (a_pstrPassword->isEmpty())
szHashedPw[0] = '\0';
else
{
/* prefix */
char *pszHashedPw = szHashedPw;
/* salt */
/* hash */
int rc = RTSha512ToString(abHash, pszHashedPw, sizeof(szHashedPw) - (pszHashedPw - &szHashedPw[0]));
}
}