From baa3553db5d8caa66f16711a8b15a59cc584ad36 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 25 Sep 2015 15:24:35 +0200 Subject: [PATCH] Add CalamaresUtils::obscure. --- src/libcalamares/utils/CalamaresUtils.cpp | 38 +++++++++++++++++++++++ src/libcalamares/utils/CalamaresUtils.h | 2 ++ src/modules/users/UsersPage.cpp | 1 + 3 files changed, 41 insertions(+) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index a5c85df0e..e7f0e5203 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -291,4 +291,42 @@ removeDiacritics( const QString& string ) } +// Function CalamaresUtils::obscure based on KStringHandler::obscure, +// part of KDElibs by KDE, file kstringhandler.cpp. +// Original copyright statement follows. +/* This file is part of the KDE libraries + Copyright (C) 1999 Ian Zepp (icszepp@islc.net) + Copyright (C) 2006 by Dominic Battre + Copyright (C) 2006 by Martin Pool + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +QString +obscure( const QString& string ) +{ + QString result; + const QChar *unicode = string.unicode(); + for ( int i = 0; i < string.length(); ++i ) + // yes, no typo. can't encode ' ' or '!' because + // they're the unicode BOM. stupid scrambling. stupid. + result += ( unicode[ i ].unicode() <= 0x21 ) ? + unicode[ i ] : + QChar( 0x1001F - unicode[ i ].unicode() ); + return result; +} + + } diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 3310da49a..c522984d9 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -52,6 +52,8 @@ namespace CalamaresUtils DLLEXPORT void setQmlModulesDir( const QDir& dir ); DLLEXPORT QString removeDiacritics( const QString& string ); + + DLLEXPORT QString obscure( const QString& string ); } #endif // CALAMARESUTILS_H diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index e1f85cdcd..ea5cdd3cb 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -128,6 +128,7 @@ UsersPage::createJobs( const QString& defaultUserGroup, const QStringList& defau gs->insert( "autologinUser", ui->textBoxUsername->text() ); gs->insert( "username", ui->textBoxUsername->text() ); + gs->insert( "password", CalamaresUtils::obscure( ui->textBoxUserPassword->text() ) ); return list; }