Ejemplo n.º 1
0
const AuthToken AuthManager::Authenticate( const std::string& username, const std::string& password, const std::string& ip )
{
	kode::db::AutoReset autoReset( m_pCheckLoginStatement );

	m_pCheckLoginStatement->Bind( "@Username", username );
	if( m_pCheckLoginStatement->GetNextRow() )
	{

		int nID = m_pCheckLoginStatement->GetColumn<int>( 0 );
		std::string encodedHash = m_pCheckLoginStatement->GetColumn<std::string>( 1 );
		std::vector< unsigned char > passwordHash( CryptoPP::SHA::DIGESTSIZE );
		kode::base64::Decode( encodedHash, passwordHash );

		//
		// Now we need to confirm the passwords match
		//
		unsigned char hashBuffer[ CryptoPP::SHA::DIGESTSIZE ];
		CryptoPP::HMAC< CryptoPP::SHA >( m_salt, sizeof( m_salt ) )
		.CalculateDigest(
		    hashBuffer,
		    &passwordHash[0],
		    passwordHash.size()
		);
		std::string hmac = kode::base64::Encode( hashBuffer, sizeof( hashBuffer ) );

		if( hmac != password )
			throw authentication_exception( "Invalid username or password" );
		return AuthToken( username, nID, AuthToken::AccessLevel_Admin );
	}
	throw authentication_exception( "Invalid username or password" );
}
Ejemplo n.º 2
0
	void Authenticator::FeedPassword (bool authFailure)
	{
		const QString& login = XmlSettingsManager::Instance ()
				.property ("lastfm.login").toString ();
		lastfm::ws::Username = login;

		if (login.isEmpty ())
			return;

		const auto& text = tr ("Enter password for Last.fm account with login %1:")
					.arg (login);
		const auto& password = Util::GetPassword ("org.LeechCraft.Lastfmscrobble/" + login,
				text,
				Proxy_,
				!authFailure);
		if (password.isEmpty ())
			return;

		const QString& authToken = AuthToken (lastfm::ws::Username, password);

		const QString& api_sig = ApiSig (lastfm::ws::ApiKey, authToken,
				"auth.getMobileSession", lastfm::ws::Username,
				lastfm::ws::SharedSecret);
		const QString& url = QString ("%1?method=%2&username=%3&authToken=%4&api_key=%5&api_sig=%6")
				.arg (ScrobblingSite)
				.arg ("auth.getMobileSession")
				.arg (lastfm::ws::Username)
				.arg (authToken)
				.arg (lastfm::ws::ApiKey)
				.arg (api_sig);

		QNetworkReply *reply = NAM_->get (QNetworkRequest (QUrl (url)));
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (getSessionKey ()));
	}
Ejemplo n.º 3
0
const AuthToken AuthManager::DefaultAuth()
{
	if( NeedsAuth() )
		throw authentication_exception( "Authentication required but no details provided" );
	return AuthToken( "default", -1, AuthToken::AccessLevel_Normal );
}