Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> SH1 / Zmiana hasła i loginu
assasin
post 31.05.2009, 20:27:23
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Witam mam baze danych która posiada 7 tysięcy użytkowników chciałbym ją połączyć w inną bazą danych która zawiera 5 tysięcy userów.
Niestety co 2 login się powtarza;/
Napisałem skrypt PHP
Cytat
<?php
$dbc = @mysql_connect ('127.0.0.1', 'root', 'root')
OR die ('Nie mogłem się połączyć: ' . mysql_error() );
@mysql_select_db ('realmd') OR die ('Nie mogłem wybrać bazy danych: ' . mysql_error() );

$sel = mysql_query("SELECT id,username FROM account");
while ($r = mysql_fetch_array($sel)) {
$r[username] .= "qwe";
$pass1 = "nokia";
$p_upper = strtoupper($pass1);
$upper = strtoupper($r[username]);
$pass = "$p_upper:$upper";
$hash = sha1($pass);
$update = "UPDATE account SET username = '$r[username]', sha_pass_hash = '$hash' WHERE id = '$r[id]'";
mysql_query($update);
echo "Dane zapisane";
}

?>

Do nazwy użytkownika dodaje qwe a hasło zmienia na nokia.
Niestety nie da się zalogować;/ rejestracja jest w SH1.
Może jakiś inny pomysł macie na powtarzające się loginy;/
Samych loginów nie mogę zmienić ponieważ w haśle jest zapisany.
Go to the top of the page
+Quote Post
golaod
post 1.06.2009, 08:59:53
Post #2





Grupa: Zarejestrowani
Postów: 419
Pomógł: 42
Dołączył: 12.08.2008
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Cytat
$pass = "$p_upper:$upper";


Cytat
...a hasło zmienia na nokia....


Jak się zastanowisz, to sam znajdziesz odpowiedź smile.gif
Go to the top of the page
+Quote Post
assasin
post 1.06.2009, 15:30:44
Post #3





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Nie wiem gdzie jest błąd;/

Ktoś ma jakiś pomysł?
Go to the top of the page
+Quote Post
Ciupaska
post 1.06.2009, 17:03:40
Post #4





Grupa: Zarejestrowani
Postów: 82
Pomógł: 0
Dołączył: 25.05.2009

Ostrzeżenie: (10%)
X----


Kod
$pass1 = "nokia";
skasuj
Go to the top of the page
+Quote Post
assasin
post 1.06.2009, 17:40:47
Post #5





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Nie działa.
Zaznaczam ze w hashu jest zapisany także login login:hasło.
Go to the top of the page
+Quote Post
nexis
post 1.06.2009, 18:08:12
Post #6





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

Ostrzeżenie: (0%)
-----


Nie bardzo wiem co chcesz osiągnąć, ale kod powinien wyglądać tak:

  1. <?php
  2. mysql_connect('127.0.0.1', 'root', 'root')
  3.    or exit('Nie mogłem się połączyć: ' . mysql_error());
  4. mysql_select_db('realmd')
  5.    or exit('Nie mogłem wybrać bazy danych: ' . mysql_error());
  6.  
  7. $query = "SELECT `id`, UPPER(`username`) AS `username` FROM `account`";
  8. $query = mysql_query($query) or exit(mysql_error());
  9. while ($result = mysql_fetch_array($query)) {
  10.    $id       = $result['id'];
  11.    $username = $result['username'] . 'QWE';
  12.    $password = sha1(sprintf('%s:%s', 'NOKIA', $username));
  13.    
  14.    $update = sprintf
  15.        (
  16.            "UPDATE `account` SET `username` = '%s', `sha_pass_hash` = '%s' WHE"
  17.             . "RE `id` = '%d'",
  18.            $username,
  19.            $password,
  20.            $id
  21.        );
  22.    if (mysql_query($update)) {
  23.        echo 'Dane zapisane';
  24.    } else {
  25.        exit(mysql_error());
  26.    }
  27. }
  28. ?>


Ten post edytował nexis 1.06.2009, 23:18:11


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post
assasin
post 1.06.2009, 18:28:58
Post #7





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Cytat
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WoW-Center_Gotowiec_rev.1.1-2.4.3\Baza\htdocs\test.php on line 9

Co chce osiągnąć?
Jak pisałem mam 2 bazy i loginy się powtarzają dlatego nie mogę jej wgrać, musze dodać do loginu jakieś znaki i wraz z tym ustawić nowe hasło ponieważ w hashu jest zapisany login. (login:hasło).

Ten post edytował assasin 1.06.2009, 18:30:38
Go to the top of the page
+Quote Post
nexis
post 1.06.2009, 23:19:53
Post #8





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

Ostrzeżenie: (0%)
-----


Cytat(assasin @ 1.06.2009, 19:28:58 ) *
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WoW-Center_Gotowiec_rev.1.1-2.4.3\Baza\htdocs\test.php on line 9

Należało przypisać wynik zapytania do zmiennej (poprawione w kodzie). Kod spełnia swoją funkcję?


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post
assasin
post 2.06.2009, 08:00:15
Post #9





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Dziwne nie da się nadal zalogować;/
Cytat
<?php

// Configuration.
// Realm database.
$r_db = "realmd";
// IP (and port).
$ip = "127.0.0.1:3306";
// Username.
$user = "trinity";
// Password.
$pass = "trinity";
// Site title.
$title = "Registration Form";
$title2 = "Some Server";
// End config.

kod html ....
function error_s ($text) {
echo("<p style=\"background-color:black;color:yellow;font-family:verdana;\">" . $text);
echo("<br /><br /><a style=\"color:orange;\" href=\"" . $_SERVER["SCRIPT_NAME"] . "\">Go back...</a></p>");
};

$user_chars = "#[^a-zA-Z0-9_\-]#";
$email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

$con = @mysql_connect($ip, $user, $pass);
if (!$con) {
error_s("Unable to connect to database: " . mysql_error());
};

if (!empty($_POST)) {
if ((empty($_POST["username"]))||(empty($_POST["password"]))||(empty($_POST["email"]))||(empty($_POST["tbc"])) ) {
error_s("You did not enter all the required information.");
exit();
} else {
$username = strtoupper($_POST["username"]);
$password = strtoupper($_POST["password"]);
$email = strtoupper($_POST["email"]);
..
KOD .5235
.. };
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$email = mysql_real_escape_string($email);
$qry = @mysql_query("select username from " . mysql_real_escape_string($r_db) . ".account where username = '" . $username . "'", $con);
if (!$qry) {
error_s("Error querying database: " . mysql_error());
};
if ($existing_username = mysql_fetch_assoc($qry)) {
foreach ($existing_username as $key => $value) {
$existing_username = $value;
};
};
$existing_username = strtoupper($existing_username);
if ($existing_username == strtoupper($_POST['username'])) {
error_s("That username is already taken.");
exit();
};
unset($qry);
$qry = @mysql_query("select email from " . mysql_real_escape_string($r_db) . ".account where email = '" . $email . "'", $con);
if (!$qry) {
error_s("Error querying database: " . mysql_error());
};
if ($existing_email = mysql_fetch_assoc($qry)) {
foreach ($existing_email as $key => $value) {
$existing_email = $value;
};
};
if ($existing_email == $_POST['email']) {
error_s("That email is already in use.");
exit();
};
unset($qry);
$sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
$register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";
$qry = @mysql_query($register_sql, $con);
if (!$qry) {
error_s("Error creating account: " . mysql_error());
};
echo("Account successfully created.");
exit();
};
} else {
echo($page);
};

?>

Tak wygląda rejestracja musiałem ją trochę skrócić.

Ten post edytował assasin 2.06.2009, 18:33:36
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.04.2024 - 03:32