Greetings!! I'm setting up a database for users who can register and then log in to allow them to change various information corresponding to the database
which is a flat text file (.db).
Example: 1|Michael Brown|24 XXX Street, London, UK|423-3429|Male|34|MrX|Secret
(ID, Full Name, Address, Tel.#, Gender, Age, User name, Password)
Right now, I only know how to alter information *all* at once. What if a user would want to change only his password? Is there a way for him to change only that without having to include everything else? I have tried to do this but always ends up erasing everything except for the password. I've tried all means but getting nowhere!
Here's what I'm asking for...
I will offer an HTML form page called 'change_password.html' which is available only if a user has already logged in. There will be four fields:
User Name: <field>
Old Password: <field>
New Password: <field>
The last <field> being hidden containing the ID#.
In my current script,
###
my (%rec) = &get_record ($in{'ID'});
###
is called to get all the information according the ID#. Each bit is signified by i.e. $rec{'ID'}, $rec{'Address'} etc. Before any changes occur, the User Name must match $rec{'Username'} and the Password must match $rec{'Password'}. Any success that I've had so far is when all fields are filled up. Otherwise, all is erased except for the information provided. Here's a piece of script that does all this (which I didn't write):
$found = 0; # Makes sure the record is in the database.
open (DB, "<record.db")
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and ($output .= $_ and next LINE);
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[$db_key_pos] eq $in{$db_key}) { # $db_key_pos re
+fers to ID# in the database I think
$output .= &join_encode(%in);
$found = 1;
}
else {
$output .= "$_\n"; # else print regular line.
}
}
close DB;
if ($found) {
open (DB, ">record.db")
if ($db_use_flock) {
flock(DB, 2)
}
print DB $output;
close DB;
&site_html_modify_success;
}
else {
&site_html_modify_failure;
}
}
sub get_record {
my ($key, $found, @data, $field);
$key = shift; $found = 0;
open (DB, "<record.db")
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[$db_key_pos] eq $key) {
$found = 1;
%rec = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
$found ? (return %rec) : (return undef);
}
sub join_encode {
my %hash = @_;
my ($tmp, $col, $output);
foreach $col (@db_cols) {
$tmp = $hash{$col};
$tmp =~ s/^\s+//g; # Trim leading blanks...
$tmp =~ s/\s+$//g; # Trim trailing blanks...
$tmp =~ s/\Q$db_delim\E/~~/og; # Change delimeter to ~~ symbo
+l.
$tmp =~ s/\n/``/g; # Change newline to `` symbol.
$tmp =~ s/\r//g; # Remove Windows linefeed char
+acter.
$output .= $tmp . $db_delim; # Build Output.
}
chop $output; # remove extra delimeter.
$output .= "\n"; # add linefeed char.
return $output;
}
sub split_decode {
my ($input) = shift;
my (@array) = split (/\Q$db_delim\E/o, $input, $#db_cols+1);
foreach (@array) {
s/~~/$db_delim/g; # Retrieve Delimiter..
s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
Please help me out with a script that could handle changing the password and nothing more without sacrificing the other bits of information! I would greatly appreciate it! Thank you in advance. If you would like more code I would gladly provide it. :-) Cheers!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.