/    Sign up×
Community /Pin to ProfileBookmark

Is my this password protection script safe from SQL injection?

Hi all,

I’ve had a bit of trouble with this script I found. Someone entered in some junk into the password field and broke my website for 15 minutes. I couldn’t get into FTP, or into my host’s control panel.

All they did was enter ==’1=1

That’s a pretty bad flaw!

I just don’t know how to apply ctype_alnum to ensure that only alphanumeric values are read by this script, so I can prevent failures like this from happening again.

Also is this script protected from SQL injection?

[ATTACH]15317[/ATTACH]

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 16.2013 — Well, if it broke when they entered that text, then it's probably not SQL injection proof. ?

The best way (IMO) is to use the MySQL[b]i[/b] or PDO database extension along with bound input parameters. If that is not feasible for some reason and you have to use the old (and now-deprecated) MySQLi extension, then you should cast any numeric field values to the appropriate type ( (int) or (float) ) or apply mysql_real_escape_string() to any character/string values.
×

Success!

Help @W8_4me spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...