T O P I C R E V I E W |
kyodai |
Posted - 02 March 2011 : 19:11:57 Well i am using the points mod and as we frequently have users annoying us with requests to have their username changed i made a neat little function for the points shop mod to have them change their username for XX points ONCE.
I added a new column to the MEMBERS table called "M_CHANGEDNAME" to record if a user already changed his/her name (We only allow ONE change per lifetime).
This replaces the avatar change item in points store, but it could also be used as a standalone mod with some work...
Search for "Case 4 'Use custom avatar" and replace the whole Case with this:
'=========
Case 4 'Use custom avatar
'actually changed to CHANGE USERNAME
'=========
CreateTable(ItemTitle)
If DoIt <> True Then
Call ShowStats()
Response.Write "<font size=""" & strFooterFontSize & """>You can only change your username ONCE IN YOUR LIFE, so better think twice before doing so.<br> DO NOT use real life names, phone numbers or anything else you might regret later on. <br>Spaces, dots or other special characters are NOT available in your new username.</font><br>"
Response.Write "<table width=""100%"" border=0><tr><td align=center>" & VbNewLine &_
"<b>Current Username: " & strDBNTUserName & "</b><br><br>" & VbNewLine
Response.Write "</td><td align=left>"
Response.Write "<br>New Username: <br><input name=""UserChange"" value=""MyNewUsername"" size=50><br>"
Response.Write "</td></tr></table>" & VbNewLine
Response.Write "<font size=""" & strFooterFontSize & """>You will NOT be able to log in with your OLD username after the change. <br>You will NEVER be able to change your username again after the change.<br> There is NO additional check so TRIPLE check for typos before submitting.</font><br>"
CloseTable(1)
Else
if not IsValidString(trim(Request.Form("UserChange"))) then
Response.Write "<br><br><li>You may not use any of these characters or a space in your Username !#$%^&*()=+{}[]|\;:/?>,<'. </li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
If Request.Form("UserChange") = "" Or len(Request.Form("UserChange")) <=2 Then
Response.Write "<br><br><li>Please enter a valid username. Minimum length is 2 characters.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
End If
'If mid(Request.Form("UserChange"), 1, 7) <> "http://" Then
' strErr = "<li>URL's must start with ""http://"""
'End If
'######check username already in use
strSql = "SELECT M_NAME FROM " & strMemberTablePrefix & "MEMBERS "
strSql = strSql & " WHERE M_NAME = '" & ChkString(Trim(Request.Form("UserChange")), "SQLString") &"'"
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
else
Response.Write "<br><br><li>Error: This Username is already taken.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
rs.close
set rs = nothing
'######end check username in use
'#####check pending
strSql = "SELECT M_NAME FROM " & strMemberTablePrefix & "MEMBERS_PENDING "
strSql = strSql & " WHERE M_NAME = '" & ChkString(Trim(Request.Form("Name")), "SQLString") &"'"
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
else
Response.Write "<br><br><li>Error: This Username is already taken.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back To Edit Data</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
rs.close
set rs = nothing
'####end check pending
'######check username already changed
strSql = "SELECT M_CHANGEDNAME FROM " & strMemberTablePrefix & "MEMBERS "
strSql = strSql & " where MEMBER_ID=" & MemberID
set rs = my_Conn.Execute (strSql)
if rs.BOF and rs.EOF then
'## Do Nothing
'wtf? nothing???
else
if rs("M_CHANGEDNAME") > 0 then
Response.Write "<br><br><li>Error: You already changed your username once. Sorry but we said ONCE IN A LIFETIME and we mean it.</li>" & vbNewLine & _
" <p align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """><a href=""JavaScript:history.go(-1)"">Go Back</a></font></p>" & vbNewLine
WriteFooter
Response.End
end if
end if
rs.close
set rs = nothing
'######end check username already changed
If strErr <> "" Then
GoError(strErr)
Else
strSql = "update " & strTablePrefix & "MEMBERS set M_NAME = '" & chkString(Request.Form("UserChange"), "SQLString") & "', " &_
"M_POINTS = M_POINTS -" & ItemCost &_
" where MEMBER_ID=" & MemberID
my_Conn.Execute (strsql)
'update change count
strSql = "update " & strTablePrefix & "MEMBERS set M_CHANGEDNAME = '1'" &_
" where MEMBER_ID=" & MemberID
my_Conn.Execute (strsql)
UpdateItemCount
Response.Write "<br>YOUR USERNAME WAS CHANGED."
Call BackToStore
End If
CloseTable(0)
End If
BEFORE the last line add the following:
Function IsValidString(sValidate)
Dim sInvalidChars
Dim bTemp
Dim i
' Disallowed characters
sInvalidChars = "!#$%^&*()=+{}[]|\;:/?>,<'"
for i = 1 To Len(sInvalidChars)
if InStr(sValidate, Mid(sInvalidChars, i, 1)) > 0 then bTemp = True
if bTemp then Exit For
next
for i = 1 to Len(sValidate)
if Asc(Mid(sValidate, i, 1)) = 160 then bTemp = True
if bTemp then Exit For
next
' extra checks
' no two consecutive dots or spaces
if not bTemp then
bTemp = InStr(sValidate, ".") > 0
end if
if not bTemp then
bTemp = InStr(sValidate, " ") > 0
end if
if not bTemp then
bTemp = (len(sValidate) <> len(Trim(sValidate)))
end if 'Addition for leading and trailing spaces
' if any of the above are true, invalid string
IsValidString = Not bTemp
End Function
I made it so the username may not contain blanks or dots (.) at all, if you wanna allow these then replace the last 2 checks with a double blankspace or period as it's in the original registration name check. |
5 L A T E S T R E P L I E S (Newest First) |
Carefree |
Posted - 04 March 2011 : 19:22:31 No hidden meaning, just prevents things like searching for a user's name to find posts ... and the user name is "the". |
kyodai |
Posted - 04 March 2011 : 18:57:33 Hmmm does this have any deeper meaning? I thought it would be a list of SQL commands and other hacking related stuff. I guess "where" and "from" are already blocked anyways due to the Chkstring...SQLString, right? |
Carefree |
Posted - 03 March 2011 : 17:35:57 Thanks. Basically the _common table is just a list of very commonly used words. Here's a dbs_common.asp to create it:
Common Word Table
[INSERT]
COMMON
(WORDLIST,REPLACE)#('0','')
(WORDLIST,REPLACE)#('1','')
(WORDLIST,REPLACE)#('2','')
(WORDLIST,REPLACE)#('3','')
(WORDLIST,REPLACE)#('4','')
(WORDLIST,REPLACE)#('5','')
(WORDLIST,REPLACE)#('6','')
(WORDLIST,REPLACE)#('7','')
(WORDLIST,REPLACE)#('8','')
(WORDLIST,REPLACE)#('9','')
(WORDLIST,REPLACE)#('a','')
(WORDLIST,REPLACE)#('am','')
(WORDLIST,REPLACE)#('and','')
(WORDLIST,REPLACE)#('are','')
(WORDLIST,REPLACE)#('be','')
(WORDLIST,REPLACE)#('being','')
(WORDLIST,REPLACE)#('but','')
(WORDLIST,REPLACE)#('down','')
(WORDLIST,REPLACE)#('for','')
(WORDLIST,REPLACE)#('from','')
(WORDLIST,REPLACE)#('had','')
(WORDLIST,REPLACE)#('has','')
(WORDLIST,REPLACE)#('have','')
(WORDLIST,REPLACE)#('her','')
(WORDLIST,REPLACE)#('hers','')
(WORDLIST,REPLACE)#('him','')
(WORDLIST,REPLACE)#('his','')
(WORDLIST,REPLACE)#('how','')
(WORDLIST,REPLACE)#('I','')
(WORDLIST,REPLACE)#('if','')
(WORDLIST,REPLACE)#('in','')
(WORDLIST,REPLACE)#('is','')
(WORDLIST,REPLACE)#('it','')
(WORDLIST,REPLACE)#('left','')
(WORDLIST,REPLACE)#('my','')
(WORDLIST,REPLACE)#('no','')
(WORDLIST,REPLACE)#('nor','')
(WORDLIST,REPLACE)#('not','')
(WORDLIST,REPLACE)#('of','')
(WORDLIST,REPLACE)#('our','')
(WORDLIST,REPLACE)#('ours','')
(WORDLIST,REPLACE)#('out','')
(WORDLIST,REPLACE)#('right','')
(WORDLIST,REPLACE)#('than','')
(WORDLIST,REPLACE)#('that','')
(WORDLIST,REPLACE)#('the','')
(WORDLIST,REPLACE)#('their','')
(WORDLIST,REPLACE)#('theirs','')
(WORDLIST,REPLACE)#('them','')
(WORDLIST,REPLACE)#('then','')
(WORDLIST,REPLACE)#('they','')
(WORDLIST,REPLACE)#('this','')
(WORDLIST,REPLACE)#('to','')
(WORDLIST,REPLACE)#('too','')
(WORDLIST,REPLACE)#('up','')
(WORDLIST,REPLACE)#('was','')
(WORDLIST,REPLACE)#('were','')
(WORDLIST,REPLACE)#('what','')
(WORDLIST,REPLACE)#('when','')
(WORDLIST,REPLACE)#('where','')
(WORDLIST,REPLACE)#('who','')
(WORDLIST,REPLACE)#('why','')
(WORDLIST,REPLACE)#('you','')
(WORDLIST,REPLACE)#('your','')
[END]
|
kyodai |
Posted - 03 March 2011 : 16:45:40 How odd, i dont even have the table prefix_common. I guess it's from a newer version?
Anyways, great work as usual, looking totally superb. Always amazed how clean your code looks. |
Carefree |
Posted - 03 March 2011 : 14:13:49 I made a stand-alone version, added a couple of things you neglected to check:
- Check if the desired name was one of the common words ("if", "and", "the", etc.).
- Next, give the option to show new username on existing posts, etc.
- Finally, FORCE a logout as soon as the name change occurs.
This allows members to change their username ONCE.
Copy both files to your forum directory, go to admin control panel, run the User NameChange from the mod drop-down menu.
"dbs_changeme.asp"
"changeme.asp"
Adding to menu(s):
|
|
|