From 2d7d1016a87e5f2538e5f09fbe1245e248b82038 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 8 Sep 2015 12:39:47 +0200 Subject: [PATCH] Better input validation for phone numbers --- telegram-purple.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/telegram-purple.c b/telegram-purple.c index 1d16c57..a0ff55c 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -563,6 +563,18 @@ static void tgprpl_login (PurpleAccount * acct) { tgl_register_app_id (TLS, TGP_APP_ID, TGP_APP_HASH); tgl_init (TLS); + + if (! tgp_startswith (purple_account_get_username(acct), "+")) { + char *cause = g_strdup_printf ("Unable to sign on as %s, phone number lacks country prefix.", + purple_account_get_username (acct)); + purple_connection_error_reason (gc, PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, cause); + purple_notify_message (_telegram_protocol, PURPLE_NOTIFY_MSG_ERROR, cause, + "Numbers must start with the full international\n" + "prefix code, e.g. +49 for Germany.", NULL, NULL, NULL); + g_free (cause); + return; + } + purple_connection_set_state (conn->gc, PURPLE_CONNECTING); telegram_login (TLS);