Discuss Scratch
- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
Right now, I'm making an OS. I thought it would be cool if I could program the game to allow you to save your password on a cloud variable, so when you re-enter the code, your username is displayed onscreen. Does anyone know how I could link the variable to someone's username so that I don't need to program a million variables for every new user? (My goal is to be able to have people enter an 8-digit pass code, and then when they enter it into the system, the variable sets the username to the correct one based on the code. I'm trying to use only one or two variables, if possible.)
-discussion is closed: thanks for the help!
-discussion is closed: thanks for the help!

Last edited by stickfiguregames01 (Nov. 26, 2013 19:41:41)
- sonicfan12p
-
Scratcher
1000+ posts
Username Sensing?
You can use only one variable if you must, but it would be easier with two. I'll come back tomorrow with some scratchblocks for you, but right now my keyboard's messed up. 

- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
You can use only one variable if you must, but it would be easier with two. I'll come back tomorrow with some scratchblocks for you, but right now my keyboard's messed up.
Awesome, thanks a ton! This will make my OS way better!
- sonicfan12p
-
Scratcher
1000+ posts
Username Sensing?
Yes. Yes it will. Especially since most people think it's impossible, and don't want to try, so you'd likely be one of the first to have this feature. 
Anyway, I'll show you how to do it with two, if you need me to do just one, then I'll make the necessary changes.
First off, you'll need a way to translate the usernames to numbers.
That script will look something like this…
And so on and so forth, continuing that pattern till you have the entire alphabet. It is of utmost importance that you encode in two character numbers, so whatever you do, don't change that.
Now, we would have a variable, My Username, that for me would look like this. 112824231812151023010225
What the heck are we going to do with that? I'll show you.
Once you make it to the end of that script, AFTER the end of the repeat block, put these blocks.
This will add your encoded username to the cloud, and it will also attempt to ensure the cloud is stable before proceeding. It's not 100%, because cloud data is still a bit glitchy, but that will help some.
Now all of this info is on the cloud, but what does that help? Nothing if we don't know how to retranslate it. Before we can retranslate it though, it's sometimes better to decompress it into a list first. That would look like this.
That would be the decompressor. Not too horribly complicated when you really think about it, and it makes retranslating just that little bit easier.
The last custom block in saving these usernames would be the retranslator itself. Its structure is similar to the first script, with a few key differences.
Here's a look at it…
Then, at the end of the repeat block, similar to the first script, we have this script.
After this step, 112824231812151023010225 has turned back into sonicfan12p. You now have your username system, but what about passwords?
You mentioned you wanted the passwords to be in 8 digit codes, making this process relatively easy. The first thing we must do is make a password, this is the script for that.
You'll see what those broadcasts do, all in good time.
That script saves the password that was created to the cloud. But it doesn't let us use that info, does it? That's what this next script does.
Now the passwords save are all in manageable form, a list. Not only that, but the item number of each password corresponds to the item number of each username.
Now that we have all our custom blocks, it's time to put them into action. First, I'll remind you what they all are. Then, we'll see where they all go, to make this thing work.
This will check to see if you already have an account. If you don't, it will create one. If you do have an account, it will ask for your password. It already knows your username, so it checks to see if you put in your account's password.
This is perfectly secure, but there's one slight catch. Having this doesn't help you if you don't save the user's preferences and settings. This requires a third variable, but I'll wait and see what you want to do about that.
If you really want it, I'll show you how to do that too, but you'll need to tell me what about your O.S. can people change and/or save.
Hope you found this helpful, Scratch On!

Anyway, I'll show you how to do it with two, if you need me to do just one, then I'll make the necessary changes.
First off, you'll need a way to translate the usernames to numbers.
That script will look something like this…
Define Translate Username
set [Counter v] to [0]
if <(length of (length of (username))) = [2]>
set [My Username v] to (length of (username))
else
set [My Username v] to (join [0] (length of (username)))
end
repeat (length of (username)
change [Counter v] by [1]
if <(letter (Counter) of (username)) = [0]
set [My Username v] to (join (My Username) [00])
end
if <(letter (Counter) of (username)) = [1]
set [My Username v] to (join (My Username) [01])
end
if <(letter (Counter) of (username)) = [2]
set [My Username v] to (join (My Username) [02])
end
if <(letter (Counter) of (username)) = [3]
set [My Username v] to (join (My Username) [03])
end
if <(letter (Counter) of (username)) = [4]
set [My Username v] to (join (My Username) [04])
end
if <(letter (Counter) of (username)) = [5]
set [My Username v] to (join (My Username) [05])
end
if <(letter (Counter) of (username)) = [6]
set [My Username v] to (join (My Username) [06])
end
if <(letter (Counter) of (username)) = [7]
set [My Username v] to (join (My Username) [07])
end
if <(letter (Counter) of (username)) = [8]
set [My Username v] to (join (My Username) [08])
end
if <(letter (Counter) of (username)) = [9]
set [My Username v] to (join (My Username) [09])
end
if <(letter (Counter) of (username)) = [a]
set [My Username v] to (join (My Username) [10])
end
if <(letter (Counter) of (username)) = [b]
set [My Username v] to (join (My Username) [11])
end
if <(letter (Counter) of (username)) = [c]
set [My Username v] to (join (My Username) [12])
end
And so on and so forth, continuing that pattern till you have the entire alphabet. It is of utmost importance that you encode in two character numbers, so whatever you do, don't change that.
Now, we would have a variable, My Username, that for me would look like this. 112824231812151023010225
What the heck are we going to do with that? I'll show you.
Once you make it to the end of that script, AFTER the end of the repeat block, put these blocks.
set [CloudBackup 1 v] to (Cloud Usernames) //your first cloud variable
set [Cloud Usernames v] to (join (Cloud Usernames) (My Username)
repeat [3]
wait [3] secs
if <not <(letter (length of (Cloud Usernames)) of (Cloud Usernames)) = (letter (length of (My Username)) of (My Username))>>
set [Cloud Usernames v] to (CloudBackup 1)
set [Cloud Usernames v] to (join (Cloud Usernames) (My Username)
end
This will add your encoded username to the cloud, and it will also attempt to ensure the cloud is stable before proceeding. It's not 100%, because cloud data is still a bit glitchy, but that will help some.
Now all of this info is on the cloud, but what does that help? Nothing if we don't know how to retranslate it. Before we can retranslate it though, it's sometimes better to decompress it into a list first. That would look like this.
Define Retranslate Cloud //You'll see this block in this script, its explanation is a bit farther down.
Define Decompress Cloud
set [Counter v] to [1]
repeat until <((Counter) + [2]) > (length of (Cloud Usernames))>
delete [all v] of [Retranslator v]
repeat (join (letter (Counter) of (Cloud Usernames)) (letter ((Counter) + [1]) of (Cloud Usernames))
change [Counter v] by [2]
add (join (letter (Counter) of (Cloud Usernames)) (letter ((Counter) + [1]) of (Cloud Usernames))) to [Retranslator v]
end
Retranslate Cloud
change [Counter v] by [2]
That would be the decompressor. Not too horribly complicated when you really think about it, and it makes retranslating just that little bit easier.
The last custom block in saving these usernames would be the retranslator itself. Its structure is similar to the first script, with a few key differences.
Here's a look at it…
Define Retranslate Cloud
set [Counter v] to [1]
set [Username Retranslator v] to (item (Counter) of [Retranslator v])
repeat (length of [Retranslator v])
change [Counter v] by [1]
if <(item (Counter) of [Retranslator v]) = [00]
set [Username Retranslator v] to (join (Username Retranslator) [0]
end
if <(item (Counter) of [Retranslator v]) = [01]
set [Username Retranslator v] to (join (Username Retranslator) [1]
end
if <(item (Counter) of [Retranslator v]) = [02]
set [Username Retranslator v] to (join (Username Retranslator) [2]
end
if <(item (Counter) of [Retranslator v]) = [03]
set [Username Retranslator v] to (join (Username Retranslator) [3]
end
if <(item (Counter) of [Retranslator v]) = [04]
set [Username Retranslator v] to (join (Username Retranslator) [4]
end
if <(item (Counter) of [Retranslator v]) = [05]
set [Username Retranslator v] to (join (Username Retranslator) [5]
end
if <(item (Counter) of [Retranslator v]) = [06]
set [Username Retranslator v] to (join (Username Retranslator) [6]
end
if <(item (Counter) of [Retranslator v]) = [07]
set [Username Retranslator v] to (join (Username Retranslator) [7]
end
if <(item (Counter) of [Retranslator v]) = [08]
set [Username Retranslator v] to (join (Username Retranslator) [8]
end
if <(item (Counter) of [Retranslator v]) = [09]
set [Username Retranslator v] to (join (Username Retranslator) [9]
end
if <(item (Counter) of [Retranslator v]) = [10]
set [Username Retranslator v] to (join (Username Retranslator) [a]
end
if <(item (Counter) of [Retranslator v]) = [11]
set [Username Retranslator v] to (join (Username Retranslator) [b]
end
if <(item (Counter) of [Retranslator v]) = [12]
set [Username Retranslator v] to (join (Username Retranslator) [c]
end
Then, at the end of the repeat block, similar to the first script, we have this script.
add (Username Retranslator) to [Users v]
After this step, 112824231812151023010225 has turned back into sonicfan12p. You now have your username system, but what about passwords?
You mentioned you wanted the passwords to be in 8 digit codes, making this process relatively easy. The first thing we must do is make a password, this is the script for that.
Define Create Password
ask [Password?] and wait
if <(Length of (answer)) = [8]>
if <<(answer) < [100000000]> and <(answer) > [9999999]>>
set [Cloud Passwords v] to (join (Cloud Passwords) (answer)
set [Counter v] to ((length of [Users v]) + [1])
broadcast [Log In v]
else
say [Your Password may not contain letters.] for [4] secs
broadcast [Password Failed v]
end
else
say [Your Password must be 8 digits.] for [3] secs
broadcast [Password Failed v]
You'll see what those broadcasts do, all in good time.

That script saves the password that was created to the cloud. But it doesn't let us use that info, does it? That's what this next script does.
Define Decompile Passwords
set [Counter v] to [0]
repeat until <(Counter) > (length of (Cloud Passwords))>
set [Password Decompiler v] to [] //yes, set it to blank.
repeat [8]
change [Counter v] by [1]
set [Password Decompiler v] to (join (Password Decompiler) (letter (Counter) of (Cloud Passwords)))
end
add (Password Decompiler) to [Passwords v]
Now the passwords save are all in manageable form, a list. Not only that, but the item number of each password corresponds to the item number of each username.
Now that we have all our custom blocks, it's time to put them into action. First, I'll remind you what they all are. Then, we'll see where they all go, to make this thing work.
Define Translate Username //Converts Username from letters to numbers
Define Decompress Cloud //Logs everyone with an account already
Define Create Password //Creates a new password
Define Decompile Passwords //Logs all existing passwords
when gf clicked
Decompress Cloud
Decompile Passwords
if <not <[Users v] contains (username)?>>
Translate Username
Create Password
else
set [Counter v] to [1]
repeat until <(item (Counter) of [Users v]) = (username)>
change [Counter v] by [1]
broadcast [Log In v]
end
When I receive [Password Failed v]
Create Password
When I receive [Log In v]
ask [What's your password?] and wait
if <(answer) = (item [Counter v] of [Passwords v])>
broadcast [Start OS v]
else
say [Wrong Password!] for [2] secs
broadcast [Log In v]
This will check to see if you already have an account. If you don't, it will create one. If you do have an account, it will ask for your password. It already knows your username, so it checks to see if you put in your account's password.
This is perfectly secure, but there's one slight catch. Having this doesn't help you if you don't save the user's preferences and settings. This requires a third variable, but I'll wait and see what you want to do about that.
If you really want it, I'll show you how to do that too, but you'll need to tell me what about your O.S. can people change and/or save.
Hope you found this helpful, Scratch On!

Last edited by sonicfan12p (Nov. 8, 2013 17:07:45)
- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
Thanks a ton! That helps me a lot! One more question: do you know if its possible to allow people to download their own music/projects/etc. into an O.S. made on Scratch? So far I haven't found a way to allow people to do that, but maybe you did?
- sonicfan12p
-
Scratcher
1000+ posts
Username Sensing?
Thanks a ton! That helps me a lot! One more question: do you know if its possible to allow people to download their own music/projects/etc. into an O.S. made on Scratch? So far I haven't found a way to allow people to do that, but maybe you did?
Well…it's not possible just from the project screen, but if one were to go into the editor they could do that. However, it wouldn't save unless they remixed your project.
There are a couple of things that one could download into the O.S. without going into the editor, and that would be raw information (notes, essays, ect.) and bit map art. This could be done by copying your code, and then pasting it back into the project when asked to import.
However, saving such things as art and text on the cloud can be very resource intensive, and very prone to corruption due to the large amount of numbers required to store that information.
Also, did you want it to save settings too?
Last edited by sonicfan12p (Nov. 8, 2013 22:56:58)
- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
Thanks a ton! That helps me a lot! One more question: do you know if its possible to allow people to download their own music/projects/etc. into an O.S. made on Scratch? So far I haven't found a way to allow people to do that, but maybe you did?
Well…it's not possible just from the project screen, but if one were to go into the editor they could do that. However, it wouldn't save unless they remixed your project.
There are a couple of things that one could download into the O.S. without going into the editor, and that would be raw information (notes, essays, ect.) and bit map art. This could be done by copying your code, and then pasting it back into the project when asked to import.
However, saving such things as art and text on the cloud can be very resource intensive, and very prone to corruption due to the large amount of numbers required to store that information.
Also, did you want it to save settings too?
Yes, I want to try to save settings like a customizable color scheme, and different apps.
(Also, I'm sure this is going to sound stupid, and the answer will probably be something I should have seen already, but how do you add a picture as your quote?
I came up with a pretty funny one, but I have it saved as a file on my computer, and I'm not sure how to get it into a post. The URL thingy isn't working, but the attach a file thingy won't do it either.)- jkibbe
-
Scratcher
32 posts
Username Sensing?
At the bottom of http://scratch.mit.edu/discuss/ you can click on ‘change your signature’ if you want to add an image or text automatically to every forum post…
- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
At the bottom of http://scratch.mit.edu/discuss/ you can click on ‘change your signature’ if you want to add an image or text automatically to every forum post…
Ok, thanks!
Last edited by stickfiguregames01 (Nov. 25, 2013 19:58:30)
- lederniersamourai
-
Scratcher
500+ posts
Username Sensing?
One important remark:
you must tell the user not to introduce their scratch password.
This is required by the “ode of conduct” of Scratch.
Young users could do that and you would be able to steal their password.
There are a lot of discussions abou that.
you must tell the user not to introduce their scratch password.
This is required by the “ode of conduct” of Scratch.
Young users could do that and you would be able to steal their password.
There are a lot of discussions abou that.
- lederniersamourai
-
Scratcher
500+ posts
Username Sensing?
This is perfectly secure, but there's one slight catch. Having this doesn't help you if you don't save the user's preferences and settings. This requires a third variable, but I'll wait and see what you want to do about that.
Cloud vars are not secure. They are designed so that anyone can see their content and can decode it.
Even a new scratcher that is not allowed to create cloud vars can see what is inside cloud vars, or even can create a script to decode what is in a cloud var.
See this: http://scratch.mit.edu/projects/14712331/
Be careful with personal info of your users.
Last edited by lederniersamourai (Nov. 25, 2013 21:06:16)
- AonymousGuy
-
Scratcher
1000+ posts
Username Sensing?
*All the scripts sonicfan12p wrote*
Em, that encode process would make me go crazy.
Instead, use scripts that generate a list of all the chars and a second of all the ids and whenever you need to decode, you just look for the letter / num combo that you are trying to encode/decode and get its equivalent out of the other list.
Hope that helps reduce the lag while editing!
- stickfiguregames01
-
Scratcher
18 posts
Username Sensing?
One important remark:
you must tell the user not to introduce their scratch password.
This is required by the “ode of conduct” of Scratch.
Young users could do that and you would be able to steal their password.
There are a lot of discussions abou that.
Well, actually, I'm not asking for their real password, I'm just writing a script so you can make your own. It's basically just a code so that the OS remembers your color settings.. To make it more secure, now that you brought that up about people entering a real password, I could write a script so that you can *only* enter an 8 number password, so that no one accidently enters a real one.

- NoMod-Test
-
Scratcher
93 posts
Username Sensing?
Is there a quicker way possibly?*facepalm* don't necropost, please.
- Hungry_Kumquat
-
Scratcher
32 posts
Username Sensing?
Is there a quicker way possibly?In case you don't know, “necroposting” means posting on a topic that's quite old.
Please, make your own topic instead of necroposting next time, okay?

Also, what do you mean by “quicker”?
This script should run pretty fast unless you're having connection problems to the Scratch servers.
If you mean an “easier” way… - cloud lists are intentionally complicated so people don't make chatrooms.
- AwesomeManJesse
-
Scratcher
48 posts
Username Sensing?
Wow, this must be old. (sorry for necroposting)
However, this is really annoying me. Instead of doing that complicated encoding and decoding process,
just do this!
or
And I know, cloud variables probably didn't exist in 2013, but I don't care.
EDIT: Nevermind, the first one won't work. I tried it and apparently only numbers can be put onto cloud variables
I'm dumb. But, however, the second one definitely will work, especially if you do this instead:
However, this is really annoying me. Instead of doing that complicated encoding and decoding process,
just do this!
when green flag clicked
set [☁ Username v] to (username)
or
when green flag clicked
add (username) to [Users v]
And I know, cloud variables probably didn't exist in 2013, but I don't care.

EDIT: Nevermind, the first one won't work. I tried it and apparently only numbers can be put onto cloud variables
I'm dumb. But, however, the second one definitely will work, especially if you do this instead:when green flag clicked
if <not <[Users v] contains (username)>> then
add (username) to [Users v]
end
Last edited by AwesomeManJesse (June 11, 2016 23:06:56)
- deck26
-
Scratcher
1000+ posts
Username Sensing?
Wow, this must be old. (sorry for necroposting)Cloud variables cannot store text, only nemeric data. That's why encoding/decoding is required.
However, this is really annoying me. Instead of doing that complicated encoding and decoding process,
just do this!when green flag clicked
set [☁ Username v] to (username)
orwhen green flag clicked
add (username) to [Users v]
And I know, cloud variables probably didn't exist in 2013, but I don't care.
- AwesomeManJesse
-
Scratcher
48 posts
Username Sensing?
Cloud variables cannot store text, only nemeric data. That's why encoding/decoding is required.Well, I realised that right after posting it.
But, in the edit I just made, I made a better one. Also, numeric*- deck26
-
Scratcher
1000+ posts
Username Sensing?
Apologies for the nemeric typo.Cloud variables cannot store text, only nemeric data. That's why encoding/decoding is required.Well, I realised that right after posting it.But, in the edit I just made, I made a better one. Also, numeric*
However adding usernames to a list has nothing to do with storing them in the cloud which is what this topic is about.










