+function verify_password($email, $password)
+{
+ /* verify password, if old password has length 32 assume it's an old md5, else use new password scheme */
+ /* return 0 if verified, else return error code
+ * 1 can't find email
+ * 2 can't calculate correct hash
+ * 3 misc error
+ */
+
+ /* check user email by getting his id */
+ $userid = DB_get_userid('email',$email);
+ if(!$userid)
+ return 1;
+
+ /* test for temporary passwords, only valid for one date (tested in the DB) */
+ $tmppasswd = md5($password);
+ if(DB_check_recovery_passwords($tmppasswd,$email))
+ return 0;
+
+ /* get saved password */
+ $existingpassword = DB_get_passwd_by_userid($userid);
+
+ if(strlen($existingpassword)==32) /* old password type */
+ {
+ if ($existingpassword == md5($password))
+ {
+ /* update password to new crypt version */
+ // create a password hash using the crypt function, need php 5.3 for this
+ // create and random salt
+ $salt = substr(str_replace('+', '.', base64_encode(sha1(microtime(true), true))), 0, 22);
+ // hash incoming password using 12 rounds of blowfish
+ $hash = crypt($password, '$2y$12$' . $salt);
+ if(strlen($hash)>13)
+ DB_query("UPDATE User SET password='$hash' where id='$userid'");
+ else
+ return 2;
+
+ return 0;
+ }
+ }
+ else
+ {
+ if ($existingpassword == crypt($password, $existingpassword))
+ return 0;
+ };
+
+ return 3;
+}
+
+/* language functions */
+function detectlanguage()
+{
+ /* read out browser's prefered language, taken from php-manual*/
+ $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ $langcode = explode(",", $langcode['0']);
+ return $langcode['0'];
+}
+
+function set_language($l,$type='lang')
+{
+ if($type=='uid')
+ {
+ $userPREF = DB_get_PREF($l);
+ $l = $userPREF['language'];
+ };
+
+ switch($l)
+ {
+ case 'de':
+ putenv("LC_ALL=de_DE");
+ setlocale(LC_ALL, "de_DE");
+ break;
+ default:
+ putenv("LC_ALL=en_US");
+ setlocale(LC_ALL, "en_US");
+ break;
+ }
+
+ // Specify location of translation tables
+ bindtextdomain("edoko", "./locale");
+ bind_textdomain_codeset("edoko", 'UTF-8');
+ // Choose domain
+ textdomain("edoko");
+
+ return;
+}
+
+function get_display_gametype($gameid)
+{
+ /* return a readable string that can be displayed to show the game type
+ * this means hiding silent solo from the user
+ */
+
+ $gametype = DB_get_gametype_by_gameid($gameid);
+
+ if ($gametype == 'normal')
+ $GT = _('normal');
+ else if($gametype=='solo')
+ {
+ $solotype = DB_get_solo_by_gameid($gameid);
+
+ switch($solotype)
+ {
+ case 'trumpless':
+ $GT = _('trumpless solo');
+ break;
+ case 'jack':
+ $GT = _('jack solo');
+ break;
+ case 'queen':
+ $GT = _('queen solo');
+ break;
+ case 'trump':
+ $GT = _('trump solo');
+ break;
+ case 'club':
+ $GT = _('club solo');
+ break;
+ case 'spade':
+ $GT = _('spade solo');
+ break;
+ case 'heart':
+ $GT = _('heart solo');
+ break;
+ case 'silent':
+ $GT = _('normal'); /* this is change compared to $gametype */
+ break;
+ }
+ }
+ else if ($gametype == 'wedding')
+ $GT = _('wedding');
+ else if ($gametype == 'poverty')
+ $GT = _('poverty');
+ else if ($gametype == 'dpoverty')
+ $GT = _('double poverty');
+
+ return $GT;
+}
+