コード例 #1
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_cost_upper()
{
    msgno = -1;
    cut_assert_null(password_hash("password", NULL, NULL, 32));
    cut_assert_null(password_hash("password", NULL, NULL, 33));
    cut_assert_null(password_hash("password", NULL, NULL, 50));
}
コード例 #2
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_cost_lower()
{
    msgno = -1;
    cut_assert_null(password_hash("password", NULL, NULL, 1));
    cut_assert_null(password_hash("password", NULL, NULL, 2));
    cut_assert_null(password_hash("password", NULL, NULL, 3));
    cut_assert_null(password_hash("password", NULL, NULL, -10));
}
コード例 #3
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_salt_short()
{
    msgno = -1;
    cut_assert_null(password_hash("password", NULL,
                                  "a", BCRYPT_BLOWFISH_COST));
    cut_assert_null(password_hash("password", NULL,
                                  "abcdefghij", BCRYPT_BLOWFISH_COST));
    cut_assert_null(password_hash("password", NULL,
                                  "abcdefghijklmnopqrst", BCRYPT_BLOWFISH_COST));
    cut_assert_null(password_hash("password", NULL,
                                  "abcdefghijklmnopqrstu",
                                  BCRYPT_BLOWFISH_COST));
}
コード例 #4
0
ファイル: player.c プロジェクト: captdeaf/pennmush
static dbref
make_player(const char *name, const char *password, const char *host,
            const char *ip)
{
  dbref player;
  char temp[SBUF_LEN];
  char *flaglist, *flagname;
  char flagbuff[BUFFER_LEN];

  player = new_object();

  /* initialize everything */
  set_name(player, name);
  Location(player) = PLAYER_START;
  Home(player) = PLAYER_START;
  Owner(player) = player;
  Parent(player) = NOTHING;
  Type(player) = TYPE_PLAYER;
  Flags(player) = new_flag_bitmask("FLAG");
  strcpy(flagbuff, options.player_flags);
  flaglist = trim_space_sep(flagbuff, ' ');
  if (*flaglist != '\0') {
    while (flaglist) {
      flagname = split_token(&flaglist, ' ');
      twiddle_flag_internal("FLAG", player, flagname, 0);
    }
  }
  if (Suspect_Site(host, player) || Suspect_Site(ip, player))
    set_flag_internal(player, "SUSPECT");
  set_initial_warnings(player);
  /* Modtime tracks login failures */
  ModTime(player) = (time_t) 0;
  (void) atr_add(player, pword_attr, password_hash(password, NULL), GOD, 0);
  giveto(player, START_BONUS); /* starting bonus */
  (void) atr_add(player, "LAST", show_time(mudtime, 0), GOD, 0);
  (void) atr_add(player, "LASTSITE", host, GOD, 0);
  (void) atr_add(player, "LASTIP", ip, GOD, 0);
  (void) atr_add(player, "LASTFAILED", " ", GOD, 0);
  snprintf(temp, sizeof temp, "%d", START_QUOTA);
  (void) atr_add(player, "RQUOTA", temp, GOD, 0);
  (void) atr_add(player, "MAILCURF", "0", GOD,
                 AF_LOCKED | AF_NOPROG | AF_WIZARD);
  add_folder_name(player, 0, "inbox");
  /* link him to PLAYER_START */
  PUSH(player, Contents(PLAYER_START));

  add_player(player);
  add_lock(GOD, player, Basic_Lock, parse_boolexp(player, "=me", Basic_Lock),
           LF_DEFAULT);
  add_lock(GOD, player, Enter_Lock, parse_boolexp(player, "=me", Basic_Lock),
           LF_DEFAULT);
  add_lock(GOD, player, Use_Lock, parse_boolexp(player, "=me", Basic_Lock),
           LF_DEFAULT);

  current_state.players++;

  local_data_create(player);

  return player;
}
コード例 #5
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_salt_binary()
{
    char *salt = NULL, *hash = NULL;
    int fd, n;
    size_t len, bytes = 0;

    len = BCRYPT_BLOWFISH_SALT_REQUIRED_LEN;

    salt = malloc(len + 1);
    memset(salt, 0, len + 1);

    fd = open("/dev/urandom", O_RDONLY);
    if (fd >= 0) {
        while (bytes < len) {
            n = read(fd, salt + bytes, len - bytes);
            if (n < 0) {
                break;
            }
            bytes += (size_t)n;
        }
        close(fd);
    }

    hash = password_hash("password", NULL, salt, BCRYPT_BLOWFISH_COST);
    cut_assert_not_null(hash);
    cut_assert_equal_int(60, strlen(hash));
    cut_assert_match("\\$2y\\$10\\$.*", hash);
    free(salt);
    free(hash);
}
コード例 #6
0
ファイル: mainwindow.cpp プロジェクト: ifaoe/daisi-gui
void MainWindow::handleAdminPass() {
	bool ok;
	QString password;
	password = QInputDialog::getText(this, tr("Admin Zugang freischalten"), tr("Passwort:"), QLineEdit::Password,QString(),&ok);
	/*
	 * MD5 sum of password
     * 5d2e35ab7e9e437b5a81a55ef8a1c895
	 */

	QCryptographicHash password_hash(QCryptographicHash::Md5);
	password_hash.addData(password.toStdString().c_str());
	if (ok ) {
		if(QString(QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex())
                == QString("5d2e35ab7e9e437b5a81a55ef8a1c895")) {
			QMessageBox message;
			message.setText(tr("Adminzugang erfolgreich freigeschaltet."));
			message.setStandardButtons(QMessageBox::Ok);
			message.exec();
			config->setAdmin(true);
		} else {
			QMessageBox message;
			message.setText("Admin Freischaltung: Falsches Passwort.");
			message.setStandardButtons(QMessageBox::Ok);
			message.exec();
		}
	}
}
コード例 #7
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_algo()
{
    char *hash = password_hash("password", "algorithm",
                               NULL, BCRYPT_BLOWFISH_COST);
    cut_assert_not_null(hash);
    cut_assert_equal_int(60, strlen(hash));
    cut_assert_match("\\$2y\\$10\\$.*", hash);
    free(hash);
}
コード例 #8
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_salt()
{
    char *hash = password_hash("password", NULL,
                               "abcdefghijklmnopqrstuv", BCRYPT_BLOWFISH_COST);
    cut_assert_not_null(hash);
    cut_assert_equal_int(60, strlen(hash));
    cut_assert_equal_string(
        "$2y$10$abcdefghijklmnopqrstuu5Lo0g67CiD3M4RpN1BmBb4Crp5w7dbK",
        hash);
    free(hash);
}
コード例 #9
0
ファイル: faction.c プロジェクト: eressea/server
faction *addfaction(const char *email, const char *password,
    const struct race * frace, const struct locale * loc)
{
    faction *f = calloc(1, sizeof(faction));
    char buf[128];

    if (!f) abort();
    if (check_email(email) == 0) {
        faction_setemail(f, email);
    } else {
        log_info("Invalid email address for faction %s: %s\n", itoa36(f->no), email?email:"");
        faction_setemail(f, NULL);
    }

    f->alliance_joindate = turn;
    f->lastorders = 0;
    f->_alive = true;
    f->password_id = 0;
    f->age = 0;
    f->race = frace;
    f->magiegebiet = 0;
    f->locale = loc;
    f->uid = 0;
    f->flags = FFL_ISNEW|FFL_PWMSG;

    if (password) {
        faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT));
        ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
    }

    f->options =
        WANT_OPTION(O_REPORT) | WANT_OPTION(O_ZUGVORLAGE) |
        WANT_OPTION(O_COMPUTER) | WANT_OPTION(O_COMPRESS) |
        WANT_OPTION(O_ADRESSEN) | WANT_OPTION(O_STATISTICS);

    f->no = unused_faction_id();
    if (rule_region_owners()) {
        alliance *al = makealliance(f->no, NULL);
        setalliance(f, al);
    }
    addlist(&factions, f);
    fhash(f);

    slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
    f->name = str_strdup(buf);

    if (!f->race) {
        log_warning("creating a faction that has no race", itoa36(f->no));
    }

    return f;
}
コード例 #10
0
ファイル: player.c プロジェクト: captdeaf/pennmush
/** Check a player's password against a given string.
 *
 *  First checks new-style formatted password strings
 *  If that doesn't match, tries old-style SHA0 password
 *  strings, and upgrades the stored password.
 *  If that doesn't match, tries really-old-style crypt(3)
 *  password strings, and upgrades the stored password.
 *  If that doesn't work, you lose.
 *
 * \param player dbref of player.
 * \param password plaintext password string to check.
 * \retval 1 password matches (or player has no password).
 * \retval 0 password fails to match.
 */
bool
password_check(dbref player, const char *password)
{
  ATTR *a;
  char *saved;

  /* read the password and compare it */
  if (!(a = atr_get_noparent(player, pword_attr)))
    return 1; /* No password attribute */

  saved = strdup(atr_value(a));

  if (!saved)
    return 0;

  if (!password_comp(saved, password)) {
    /* Nope. Try SHA0. */
    char *passwd = mush_crypt_sha0(password);
    if (strcmp(saved, passwd) != 0) {
/* Not SHA0 either. Try old-school crypt(); */
#ifdef HAVE_CRYPT
      if (strcmp(crypt(password, "XX"), saved) != 0) {
/* Nope */
#endif /* HAVE_CRYPT */
        /* See if it's a MUX password */
        if (!check_mux_password(saved, password)) {
          /* As long as it's not obviously encrypted, check for a
           * plaintext password. */
          if (strlen(password) < 4 || *password == '$' ||
              (password[0] == 'X' && password[1] == 'X') ||
              strcmp(saved, password)) {
            free(saved);
            return 0;
          }
        }
#ifdef HAVE_CRYPT
      }
#endif
    }
    /* Something worked. Change password to SHS-encrypted */
    do_rawlog(LT_CONN, "Updating password format for player #%d", player);
    (void) atr_add(player, pword_attr, password_hash(password, NULL), GOD, 0);
  }
  /* Success! */
  free(saved);
  return 1;
}
コード例 #11
0
ファイル: login.c プロジェクト: w0dm4n/dofusproject
int check_account(char *account, char *password, char *hc_key)
{
  MYSQL_RES* res;
  MYSQL_ROW* row;
  char query[300] = "\0";
  char *key;
  char parse_hckey[2] = "HC";
  char parse_encrypted_pwd[2] = "#";
  char *encrypted_pwd_rcv;
  char *encrypted_pwd_sql;
  int status;
  int ban_status;

  status = FALSE;
  key = strtok(hc_key, parse_hckey);
  encrypted_pwd_rcv = strtok(password, parse_encrypted_pwd);
  //query = (char)malloc(sizeof(char) * 124);
  // query = "SELECT * FROM accounts WHERE \"";
  strcat(query, "SELECT * FROM accounts WHERE account =\"");
  strcat(query, account);
  strcat(query, "\"");
  res = exec_mysql(query);
  if (res)
    {
      while ((row = mysql_fetch_row(res)) != NULL)
	{
	  if (!strcmp((char*)row[1], account))
	    {
	      ban_status = atoi(row[7]);
	      encrypted_pwd_sql = password_hash(row[2], key);
	      if (!strcmp(encrypted_pwd_rcv, encrypted_pwd_sql))
		  status = TRUE;
	      if (ban_status != 0)
		  status = 2;
		break;
	    }
	}
    }
  mysql_free_result(res);
  return (status);
}
コード例 #12
0
ファイル: player.c プロジェクト: captdeaf/pennmush
/** Change a player's password.
 * \verbatim
 * This function implements @password.
 * \endverbatim
 * \param executor the executor.
 * \param enactor the enactor.
 * \param old player's current password.
 * \param newobj player's desired new password.
 * \param queue_entry the queue entry \@password is being executed in
 */
void
do_password(dbref executor, dbref enactor, const char *old, const char *newobj,
            MQUE *queue_entry)
{
  if (!queue_entry->port) {
    char old_eval[BUFFER_LEN];
    char new_eval[BUFFER_LEN];
    char const *sp;
    char *bp;

    sp = old;
    bp = old_eval;
    if (process_expression(old_eval, &bp, &sp, executor, executor, enactor,
                           PE_DEFAULT, PT_DEFAULT, NULL))
      return;
    *bp = '\0';
    old = old_eval;

    sp = newobj;
    bp = new_eval;
    if (process_expression(new_eval, &bp, &sp, executor, executor, enactor,
                           PE_DEFAULT, PT_DEFAULT, NULL))
      return;
    *bp = '\0';
    newobj = new_eval;
  }

  if (!password_check(executor, old)) {
    notify(executor, T("The old password that you entered was incorrect."));
  } else if (!ok_password(newobj)) {
    notify(executor, T("Bad new password."));
  } else {
    (void) atr_add(executor, pword_attr, password_hash(newobj, NULL), GOD, 0);
    notify(executor, T("You have changed your password."));
  }
}
コード例 #13
0
void eapol_am_wlan_authentication_symbian_c::ReadWPASettingsL()
{
	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::ReadWPASettingsL(): %s, this = 0x%08x => 0x%08x\n"),
		 (m_is_client == true) ? "client": "server",
		 this,
		 dynamic_cast<abs_eap_base_timer_c *>(this)));
	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_am_wlan_authentication_symbian_c::ReadWPASettingsL()");

	eap_status_e status(eap_status_ok);

	if (m_selected_eapol_key_authentication_type == eapol_key_authentication_type_WPS)
	{
		EAP_TRACE_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT, (EAPL("WPS does not use CommDbIf anymore.\n")));
		return;
	}

	TIndexType index_type(ELan);
	TUint index(0UL);

	status = read_database_reference_values(
		&index_type,
		&index);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
	}

	if (index_type == ELan)
	{
		EAP_TRACE_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("WLAN settings: m_WPA_override_enabled=%d\n"),
			m_WPA_override_enabled));

		EAP_TRACE_DATA_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("m_wpa_preshared_key"),
			m_wpa_preshared_key.get_data(),
			m_wpa_preshared_key.get_data_length()));

		EAP_TRACE_DATA_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("m_SSID"),
			m_SSID.get_data(),
			m_SSID.get_data_length()));

		// Get WPA pre shared key & SSID
		if (m_is_client == true
			&& (m_selected_eapol_key_authentication_type == eapol_key_authentication_type_RSNA_PSK
				|| m_selected_eapol_key_authentication_type == eapol_key_authentication_type_WPA_PSK))
		{
			TPSKEntry pskEntry;
			pskEntry.indexType = index_type;
			pskEntry.index = index;
			pskEntry.ssid.Zero();
			pskEntry.password.Zero();
			pskEntry.psk.Zero();

            TInt error(KErrNone);

			// Retrieve saved PSK only when override is not in effect
			TRAP(error, RetrievePSKL(pskEntry));
			
			if (error != KErrNone
				|| m_SSID.compare(pskEntry.ssid.Ptr(), pskEntry.ssid.Size()) != 0
				|| m_wpa_preshared_key.compare(pskEntry.password.Ptr(), pskEntry.password.Size()) != 0)
			{
				// No previous PSK or parameters were changed.
				// We need to calculate PSK again
				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("No previous PSK found...\n")));

				crypto_wpa_psk_password_hash_c password_hash(m_am_tools);

				if (m_wpa_preshared_key.get_data_length() == 2ul*EAPOL_WPA_PSK_LENGTH_BYTES)
				{
					// This is hex ascii 64-digit WWPA-PSK.
					// Convert it to 32 octets.
					u32_t target_length(EAPOL_WPA_PSK_LENGTH_BYTES);

					status = m_wpa_preshared_key_hash.set_buffer_length(EAPOL_WPA_PSK_LENGTH_BYTES);
					if (status != eap_status_ok)
					{
						send_error_notification(eap_status_key_error);
						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
					}

					status = m_wpa_preshared_key_hash.set_data_length(EAPOL_WPA_PSK_LENGTH_BYTES);
					if (status != eap_status_ok)
					{
						send_error_notification(eap_status_key_error);
						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
					}

					status = m_am_tools->convert_hex_ascii_to_bytes(
						m_wpa_preshared_key.get_data(m_wpa_preshared_key.get_data_length()),
						m_wpa_preshared_key.get_data_length(),
						m_wpa_preshared_key_hash.get_data(EAPOL_WPA_PSK_LENGTH_BYTES),
						&target_length);
					if (status != eap_status_ok
						|| target_length != EAPOL_WPA_PSK_LENGTH_BYTES)
					{
						send_error_notification(eap_status_key_error);
						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
					}
				}
				else
				{
					status = password_hash.password_hash(
						&m_wpa_preshared_key,
						&m_SSID,	
						&m_wpa_preshared_key_hash,
						0,
						0);

					if (status != eap_status_ok)
					{
						send_error_notification(eap_status_key_error);
						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
					}
				}

				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("new WPA-PSK SSID"),
					m_SSID.get_data(),
					m_SSID.get_data_length()));
				
				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("new WPA-PSK preshared key"),
					m_wpa_preshared_key.get_data(),
					m_wpa_preshared_key.get_data_length()));
				
				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("new WPA-PSK hash"),
					m_wpa_preshared_key_hash.get_data(),
					m_wpa_preshared_key_hash.get_data_length()));
				
				// Save new PSK.
				pskEntry.ssid.Copy(
					m_SSID.get_data(),
					m_SSID.get_data_length()
					);
			
				pskEntry.password.Copy(
					m_wpa_preshared_key.get_data(),
					m_wpa_preshared_key.get_data_length()
					);
				
				pskEntry.psk.Copy(
					m_wpa_preshared_key_hash.get_data(),
					m_wpa_preshared_key_hash.get_data_length()
					);

				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Saving PSK.\n")));

				SavePSKL(pskEntry);
			}
			else
			{
				// Copy retrieved WPAPSK hash to member variable
				status = m_wpa_preshared_key_hash.set_copy_of_buffer(pskEntry.psk.Ptr(), pskEntry.psk.Size());
				if (status != eap_status_ok)
				{
					send_error_notification(eap_status_key_error);
					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
					User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)));
				}

				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("old WPA-PSK SSID"),
					m_SSID.get_data(),
					m_SSID.get_data_length()));
				
				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("old WPA-PSK preshared key"),
					m_wpa_preshared_key.get_data(),
					m_wpa_preshared_key.get_data_length()));
				
				EAP_TRACE_DATA_DEBUG(
					m_am_tools,
					TRACE_FLAGS_DEFAULT,
					(EAPL("old WPA-PSK hash"),
					m_wpa_preshared_key_hash.get_data(),
					m_wpa_preshared_key_hash.get_data_length()));
			}
		}
	} 
	else
	{
		// At the moment only LAN bearer is supported.
		User::Leave(KErrNotSupported);
	}

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
}
コード例 #14
0
ファイル: player.c プロジェクト: captdeaf/pennmush
/** Attempt to register a new player at the connect screen.
 * If registration is allowed, a new player object is created with
 * a random password which is emailed to the registering player.
 * \param name name of player to register.
 * \param email email address to send registration details.
 * \param host host from which registration is being attempted.
 * \param ip ip address from which registration is being attempted.
 * \return dbref of created player or NOTHING if creation failed.
 */
dbref
email_register_player(DESC *d, const char *name, const char *email,
                      const char *host, const char *ip)
{
  char *p;
  char passwd[20];
  static char elems[] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  int i, len;
  bool resend = 0;
  dbref player = NOTHING;
  FILE *fp;
  size_t NELEMS = sizeof(elems) - 1;
  char sbuff[260];

  if (!check_fails(ip)) {
    return NOTHING;
  }

  if (strlen(options.sendmail_prog) == 0)
    return NOTHING;

  if (!ok_player_name(name, NOTHING, NOTHING)) {
    /* Check for re-registration request */
    player = lookup_player(name);
    if (GoodObject(player)) {
      ATTR *a;
      a = atr_get(player, "LASTLOGOUT");
      if (!a) {
        a = atr_get(player, "REGISTERED_EMAIL");
        if (a && !strcasecmp(atr_value(a), email))
          resend = 1;
      }
    }
    if (!resend) {
      do_log(LT_CONN, 0, 0, "Failed registration (bad name) from %s", host);
      queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s",
                  d->descriptor, ip, mark_failed(ip), "register: bad name",
                  name);
      return NOTHING;
    }
  }
  if (!resend) {
    /* Make sure that the email address is kind of valid. A valid
     * address must contain a @. Let the mailer sort it out beyond
     * that.  Also, to prevent someone from using the MUSH to mailbomb
     * another site, let's make sure that the site to which the user
     * wants the email sent is also allowed to use the register
     * command.  If there's an @, we check whatever's after the last @
     * (since @foo.bar:user@host is a valid email).
     */
    if ((p = strrchr(email, '@'))) {
      p++;
      if (!Site_Can_Register(p)) {
        if (!Deny_Silent_Site(p, AMBIGUOUS)) {
          do_log(LT_CONN, 0, 0,
                 "Failed registration (bad site in email: %s) from %s", email,
                 host);
          queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s",
                      d->descriptor, ip, mark_failed(ip),
                      "register: bad site in email", name);
        }
        return NOTHING;
      }
    } else {
      if (!Deny_Silent_Site(host, AMBIGUOUS)) {
        do_log(LT_CONN, 0, 0, "Failed registration (bad email: %s) from %s",
               email, host);
        queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s",
                    d->descriptor, ip, mark_failed(ip),
                    "register: sitelocked host", name);
      }
      return NOTHING;
    }

    if (DBTOP_MAX && (db_top >= DBTOP_MAX + 1) && (first_free == NOTHING)) {
      /* Oops, out of db space! */
      do_log(LT_CONN, 0, 0, "Failed registration (no db space) from %s", host);
      queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s",
                  d->descriptor, ip, count_failed(ip),
                  "register: no db space left to create!", name);
      return NOTHING;
    }
  }

  /* Come up with a random password of length 7-12 chars */
  len = get_random_u32(7, 12);
  for (i = 0; i < len; i++)
    passwd[i] = elems[get_random_u32(0, NELEMS - 1)];
  passwd[len] = '\0';

  /* If we've made it here, we can send the email and create the
   * character. Email first, since that's more likely to go bad.
   * Some security precautions we'll take:
   *  1) We'll use sendmail -t, so we don't pass user-given values to a shell.
   *  2) We'll cross our fingers and hope nobody uses this to spam.
   */

  release_fd();
  snprintf(sbuff, sizeof sbuff, "%s -t", options.sendmail_prog);
  if ((fp = popen(sbuff, "w")) == NULL) {
    do_log(LT_CONN, 0, 0,
           "Failed registration of %s by %s: unable to open sendmail", name,
           email);
    queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s,%d",
                d->descriptor, ip, count_failed(ip),
                "register: Unable to open sendmail!", name, 1);
    reserve_fd();
    return NOTHING;
  }
  fprintf(fp, "Subject: ");
  fprintf(fp, T("[%s] Registration of %s\n"), MUDNAME, name);
  fprintf(fp, "To: %s\n", email);
  fprintf(fp, "Precedence: junk\n");
  fprintf(fp, "\n");
  fprintf(fp, T("This is an automated message.\n"));
  fprintf(fp, "\n");
  fprintf(fp, T("Your requested player, %s, has been created.\n"), name);
  fprintf(fp, T("The password is %s\n"), passwd);
  fprintf(fp, "\n");
  fprintf(fp, T("To access this character, connect to %s and type:\n"),
          MUDNAME);
  fprintf(fp, "\tconnect \"%s\" %s\n", name, passwd);
  fprintf(fp, "\n");
  i = pclose(fp);
  reserve_fd();

  if (i != 0) {
    /* Mailer exited with an error code. Log it. */
    do_rawlog(
      LT_CONN,
      "When attempting to email a password to a newly registered player,\n"
      "\tthe mailer exited with error code %d.\n"
      "\t(Check /usr/include/sysexits.h if present for the meaning.)",
      i);
    queue_event(SYSEVENT, "SOCKET`CREATEFAIL", "%d,%s,%d,%s,%s,%d",
                d->descriptor, ip, count_failed(ip),
                "register: Unable to send email", name, i);
    return NOTHING;
  } else if (resend) {
    /* Reset the password */
    (void) atr_add(player, pword_attr, password_hash(passwd, NULL), GOD, 0);
    return player;
  } else {
    /* Ok, all's well, make a player */
    player = make_player(name, passwd, host, ip);
    queue_event(SYSEVENT, "PLAYER`CREATE", "%s,%s,%s,%d,%s",
                unparse_objid(player), name, "register", d->descriptor, email);
    (void) atr_add(player, "REGISTERED_EMAIL", email, GOD, 0);
    return player;
  }
}
コード例 #15
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_only_cost()
{
    msgno = -1;
    cut_assert_null(password_hash(NULL, NULL, NULL, BCRYPT_BLOWFISH_COST));
}
コード例 #16
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_only_salt()
{
    msgno = -1;
    cut_assert_null(password_hash(NULL, NULL, "salt", 0));
}
コード例 #17
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_only_algo()
{
    msgno = -1;
    cut_assert_null(password_hash(NULL, BCRYPT_BLOWFISH, NULL, 0));
}
コード例 #18
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_only_password()
{
    msgno = -1;
    cut_assert_null(password_hash("password", NULL, NULL, 0));
}
コード例 #19
0
ファイル: hash.c プロジェクト: kjdev/php-password-hashing
void
test_args_none()
{
    cut_assert_null(password_hash(NULL, NULL, NULL, 0));
}
コード例 #20
0
ファイル: faction.c プロジェクト: eressea/server
char *faction_genpassword(faction *f, char *buffer) {
    password_generate(buffer, 8);
    faction_setpassword(f, password_hash(buffer, PASSWORD_DEFAULT));
    ADDMSG(&f->msgs, msg_message("changepasswd", "value", buffer));
    return buffer;
}