/*
- * Copyright (C) 2005-2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2016 Andrea Zagli <azagli@libero.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
static gchar
-*controllo ()
+*controllo (const gchar *username, const gchar *password, const gchar *new_password)
{
gchar *sql;
- gchar *utente = "";
- gchar *password;
- gchar *password_nuova;
GdaDataModel *dm;
- utente = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_utente))));
- password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password))));
-
sql = g_strdup_printf ("SELECT code"
" FROM users"
" WHERE code = '%s'"
" AND password = '%s'"
" AND status <> 'E'",
- gdaex_strescape (utente, NULL),
+ gdaex_strescape (username, NULL),
gdaex_strescape (zak_authe_db_encrypt_password (password), NULL));
dm = gdaex_query (gdaex, sql);
g_free (sql);
g_warning ("User name or password aren't valids.");
return NULL;
}
+ if (dm != NULL)
+ {
+ g_object_unref (dm);
+ }
- utente = g_strstrip (g_strdup (gdaex_data_model_get_field_value_stringify_at (dm, 0, "code")));
-
- if (strcmp (utente, "") != 0
- && gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio)))
+ if (new_password != NULL)
{
- password_nuova = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_nuova))));
- if (strlen (password_nuova) == 0 || strcmp (g_strstrip (password_nuova), "") == 0)
+ gchar *_new_password = g_strstrip (g_strdup (new_password));
+ if (strlen (_new_password) == 0 || g_strcmp0 (_new_password, "") == 0)
{
/* TO DO */
g_warning ("The new password cannot be empty.");
}
- else if (strcmp (g_strstrip (password_nuova), g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))))) != 0)
- {
- /* TO DO */
- g_warning ("The new and confirm password don't match.");
- }
else
{
/* cambio la password */
sql = g_strdup_printf ("UPDATE users"
" SET password = '%s'"
" WHERE code = '%s'",
- gdaex_strescape (zak_authe_db_encrypt_password (password_nuova), NULL),
- gdaex_strescape (utente, NULL));
+ gdaex_strescape (zak_authe_db_encrypt_password (_new_password), NULL),
+ gdaex_strescape (username, NULL));
if (gdaex_execute (gdaex, sql) == -1)
{
/* TO DO */
+ g_free (sql);
g_warning ("Error changing password.");
return NULL;
}
+ g_free (sql);
}
}
- return utente;
+ return g_strdup (username);
}
static void
GError *error;
gchar *ret = NULL;
+ gchar *utente;
+ gchar *password;
+ gchar *new_password;
+
error = NULL;
get_gdaex (parameters);
{
case GTK_RESPONSE_OK:
/* controllo dell'utente e della password */
- ret = controllo ();
+ password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password))));
+ utente = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_utente))));
+ new_password = NULL;
+ if (gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio)))
+ {
+ new_password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_nuova))));
+ if (strcmp (g_strstrip (new_password), g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))))) != 0)
+ {
+ /* TO DO */
+ g_warning ("The new and confirm password don't match.");
+ g_free (new_password);
+ new_password = NULL;
+ }
+ }
+ ret = controllo (utente, password, new_password);
break;
case GTK_RESPONSE_CANCEL:
return ret;
}
+/**
+ * zak_authe_plg_authe_nogui:
+ * @parameters:
+ * @username:
+ * @password:
+ * @new_password:
+ *
+ */
+gboolean
+zak_authe_plg_authe_nogui (GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password)
+{
+ gboolean ret;
+
+ gchar *_username;
+
+ get_gdaex (parameters);
+ if (gdaex == NULL)
+ {
+ return FALSE;
+ }
+
+ /* inizializzo libgcrypt */
+ gcry_check_version (GCRYPT_VERSION);
+
+ _username = controllo (username, password, new_password);
+ if (_username != NULL
+ && g_strcmp0 (_username, "") != 0)
+ {
+ ret = TRUE;
+ }
+ else
+ {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
/**
* get_management_gui:
* @parameters:
--- /dev/null
+/*
+ * Copyright (C) 2016 Andrea Zagli <azagli@libero.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+#include <libzakauthe.h>
+
+int
+main (int argc, char **argv)
+{
+ ZakAuthe *aute;
+ GSList *params;
+
+ gtk_init (&argc, &argv);
+
+ aute = zak_authe_new ();
+
+ params = NULL;
+
+ /* the libaute module to use */
+ params = g_slist_append (params, argv[1]);
+ /* the libgda connection string */
+ params = g_slist_append (params, argv[2]);
+
+ zak_authe_set_config (aute, params);
+
+ g_message ("User %s\n", zak_authe_authe_nogui (aute, argv[3], argc >= 5 ? argv[4] : "", argc >= 6 ? argv[5] : NULL) ? argv[3] : NULL);
+
+ return 0;
+}