Okay, so I wanted to record this video. I am fairly new to Unity and I'm trying to develop a 2D side-scroller with some character animation and So I'm developing my character and I started initially by Finding spreadsheets from different games. I found one from Prince of Persia and I was trying to kind of copy the motion of the character from that and Show how he animates and just sort of trace over his motions with my own characters motions And it was kind of sloppy and wiggly and I'm not the best an illustrator So I was looking for a better way to create 2D side-scroller animation. I Found a decent workflow. It could definitely be improved And if you have any ideas of how to do so, please get in touch But this is the workflow that I found Hopefully it'll be useful to someone else And it starts in fuse, which is a fairly new offering from Adobe if you have the creative cloud membership Which includes Photoshop, Illustrator and Premiere Pro and things like that. It's included in that so you can just open your creative cloud installer and Download that It's here in apps Fuse so I have it obviously otherwise it would say install Once that's installed you can open it up and build your character and it starts by just sort of like Dragging these Characters in there so slow You know and you just click on the parts of the Character that best matched what you were trying to create Obviously you can really tweak this So this is just a quick and dirty Female character with some funny mismatched legs really bad Weird farmer's tan. Anyway, that's not my character. I want to open mine, which is a Model I made to resemble my friend Matt who is walking every street in the city of New York and this game is going to be about him He has a really cool blog called. I'm just walking calm check it out If you get a chance Meantime here's my character. I won't go too much into fuse But basically once you have this character you can go to customize and you can tweak all sorts of different things you know you can Change hand positions and how wide their jaw is and how what shape their eyes are and Things like that you can give them clothes It's a little bit limited and if they don't have what you need as far as I know There's no way to get more currently Maybe there's a way to build it yourself and submit it So you kind of stuck with what they gave you but with that you can do a lot so I made this character and After I built him I Click this save to mix-a-mo now mix-a-mo is sort of I think it must have been bought out by Adobe and sort of Piled in with fuse it seems like it's in this sort of Transitory state where it's still called mix-a-mo, but it's it's part of Adobe. Anyway, once you export this character He will find him in here and this is just sort of like this is the first thing you'll see is your character Once this loads you'll see he has a sort of resting pose and you can give him all these animations and the animations I've been uploaded to the mix-a-mo database and are You know being added on a regular basis These are all the animations my character can go through you can see the character has changed slightly I started with this and those still seem to be in this database. I could probably get rid of them at this point But all of these up here are my character's animation. So I have him jogging jumping Climbing stairs sitting down etc You want to find more animations? You just go in here and search. So you describe the action you want them to do Let's say we want them to hang So these are all kinds of hanging animations Some of them are better than others Some seem a little messed up and you can just pick one and Your character will do it Climb out. This is him kind of shimmying along a bar or something like that And once you have it you can click add to assets or if you want to download a bunch at a time You sort of add it you click add to pack and then you can download them all in bulk So, you know again if I were to go back to Here and downloads. I'll see you know, I had created this pack with which had a whole bunch of Assets and then I added one called jumping up So that's just an individual and it outputs them as fbx, which is useful in all kinds of 3d programs I'm going to be using cinema 4d and the reason I'm using that is I'm going to Within cinema 4d. I'm going to output an image sequence So this is a blank scene in cinema 4d. We're just going to open up the character That was exported from mixamo There was a whole bunch exported, but I'm going to open up the main one, which is matte dot fbx for my for me I'm going to leave all these defaults And here's our character in his default t-pose And you can see he's got this weird glow He also doesn't look quite like the character of mixamo and I'm not sure why that is but if you go highlight all your materials and Click on this basic tab here and uncheck specular You'll get rid of that glow So now you got your guy you can see Not only do you have the shaded character, but you have this sort of spine running through them. That's the Skeleton, so I'm going to create a null Just to hold the character call it character and We'll bring all this into there so that we can Hide it real quick and see that skeleton So this is you know if you wanted to pose this guy manually you could do that You could turn your character back on you can see he's got to do in the phone Do in the wave or something like that? anyway So that's that let's turn him back on and We're gonna be creating a side scroller again, so I'm gonna use a left view and this is the view I'm gonna use to Sort of render out my character And all of his animations for my game So I'm gonna call this t-pose, but we need to bring in all the other skeletons that have animations and so The way that I would do that is go to file Merge and then let's pick. Let's pick one Let's pick a jog for it. I'm gonna merge that in and Really, I think all we need is The animation not positive. Let's see what happens when I just bring that in and select a default All right, so we'll call this jog and We need it. We have it here and if we All right, this is only one frame. Let's say 30 You can see I don't know much about center for you. Okay, so if we move forward here You can see we've got our we got 25 frames here of jogging excitement of Skeleton, but not our character. Let me make sure there's no more. Yeah, he stops at 25. So let's make this 25 long So we need to tie that to the skeleton and the way we do that is with a Retargeting tags and I need to find it here Which is not always easy to do No, but it's here in character tags. So character retarget and our target is gonna be t-pose and Our source is gonna be jog So now all we have to do is drag those into the proper fields and we've got our running character So now we can just export this from Center for 4d and we would have a series of We want to create an image sequence. So we'd have this image sequence That we could use to compile a running animation in unity 4d Eventually what we want to end up with a sprite sheet But I want to do a couple of things before I output that sprite sheet One is that I want to give my character a style So I'm looking for this sketch in tune shader So I'm not exactly sure where to find it The texture sketch in tune. Where is that shader? I think it's the sketch material. There we go And the other thing I'm gonna do is a Interactive render region This allows us to see in real time what everything's gonna look like with the shaders applied So this is what we've got with the default sketch in tune shader And you could tweak this. There's a lot of things a Don't like about this I'm not gonna waste too much time on it because your desires for shading might be different but the main thing I want to do is in Render settings Sketch in tune. I want to make sure that this is a transparent Outputs transparent PNGs. So in the Shading the background We just want to turn the turn it from color to off There we go, and it's gonna show up black, but when it outputs, it's going to be transparent. So that's all I need for sketch in tune and Here in my output settings, I'm gonna just leave this for 800 by 600 You could change it to be whatever you want and in render region We actually want to use that interactive render region and we want to set it to the size That it's gonna be for that full-run animation. So I'll still need to adjust that but Since we're in this menu, we'll just take a look at the rest of the options here The default format for output is TIFF, but we want to do PNGs and Let's include the alpha channel And That's good. You would then choose where you want to save it Just set it up to Go to my desktop And I'm good So now I could output the scene and I would have a series of PNGs I'll show you that in a second, but there's one other thing that I'd like to show you and that is an additional tag I don't like this sort of Dithered look on my character and to get a really nice flat look which is what I'm after I Want to find the matte material Shader. I have to find that I have no idea where it would be Compositing. Oh, it's a compositing tag Matte object, and then we just would set the color that we want there So, you know, this might take a while to do but I just do a quick and dirty like this is roughly Skin color I'd be after for his face and then I could You know Apply that to his shirt. Whoops. I'm really slow at this guys. I'm sorry, but hopefully this time will be a little A little bit faster add another compositing tag. I'm sure there's a way to copy these down and not be So dang slow But anyway, say we wanted to give him a red shirt And we give him a red shirt And you know I'd go through the whole character and Given the styles that I want this slider here turns up the quality so Be set up and as I mentioned you want to make sure your render region is a Set to capture the whole character animation. It looks like he runs to about here. So that's fine Anyway, so then I would go to render to picture viewer You would output all the PNG's and then we could compile those into a spreadsheet now Again There's probably multiple ways to do this But I found a sprite sheet creator online that's free and works pretty decent So I'm going to do that but what you start with Here is my jog sequence and It's just a bunch of PNG's you can see I'm sort of scrolling through them in the finder here They're all output. They're all transparent We want to put them all together So once we go to the sub mind sprite sheet creator, we'll end up with something like this which has them all on one document So I use this app called stitches. You can search for it on Google You could just simply Open it up select all your PNG's and They would get Let's go ahead and do it They would get put here And the only thing I don't love about this, but I haven't figured out a way around it Maybe you have a better better resource you could share with me is that it doesn't quite put them in order So you can see we've got matte jump zero here Matt jump one here Then it goes to Matt jump 10 and Matt jump seven so it seems to be maybe Outputting them in the order that they get uploaded not necessarily in a numerical order You know four five Six Nine so ideally they would just be one two three four next line five six seven eight, etc But anyway, once you've got that the way you want it you just click download spreadsheet And once you have that spreadsheet you could bring it into unity now Here I am in unity If I drag that spreadsheet in I'll get something that looks like this you can see I've got my jog spreadsheet And by default Those will be set to single you'll want to select So Click that sprite mode button and change them to multiple Apply those changes here, and I go to your spread editor So this is my spread editor and Within that I could now slice This spread up and if you keep it as odd up you could manually do it by cell count So you could say there's four rows and four columns or You know if you knew the pixel width of each one you could set it that way I'm just gonna do automatic does this nice thing where it sort of finds the edges fits them down as small as it can and So you know each character has its little box and that's gonna be it's gonna be its own cell of the animation for our jog animation and And so the next thing we need to do is just I wrote down which numbers these are since they weren't output in order From that stitches up so my frames were zero one ten seven Then the next row was from eleven frame two frame three from eight, etc. So Bear with me here, but I would need to rename all these so that's Jogs bright sheets zero jogs bright sheet one jogs bright sheet ten Score them all here, and it seems like unity likes this Naming convention, and if you use straight from that it has a hard time Being able to put together the animations that you need so Just know now let's go back to that seven and again, this is gonna be different for you, but For me, this is how it created the spreadsheet to keep myself from getting confused or getting a janky animation Need to make sure they're named properly once that set you click apply here Create our spreadsheet. So now you can see each one of these here Is a different frame of the animation now my game has it's sort of animator component from unity Built in and the way that I got that is Once you have created this spreadsheet if you drag it into your scene for the very first time you will automatically Receive an animator component and your animation built for you by unity since I already have that I'm gonna do that But let's take a look at what my animator looks like So I have a bunch of stuff in here that I've already rigged up and if I play my scene You'll get a better sense of what I've got going. So I've got this walk animation that I already built which was done from fuse and mix-a-mo from the workflow you just saw if I'm running and Hit the jump button if I'm walking and hit the jump button the character jumps if I'm standing still jump He does this funny Jump animation and I'm using physics from unity So I'm using the rigid body 2d physics the box 2d physics that comes included with unity. I don't love it Seems a little bit like the characters on the moon. I Would love to rig up my own physics engine and I may do that down the road But for now, I'm just using the simple easy physics from unity And it's got things like if we look at it here rigid body 2d You can give your character a mess. You can give them Drag you can mess with gravity things like that and that will all affect kind of how the scene looks So you could tweak that and try to get a little bit closer to the animation you're looking for And you could also tween the individual spreadsheets so Say I wanted to create that jog animation I would go in here and I do create state and there's two options here, and they're very different I'm using actually a blend tree for most of my animations, but for this one. I'm just going to do an empty state a Blend tree makes sure that essentially if your character needs to execute all of the frames of animation In one span so like with our jump animation if he needs to go through that full range of motion before he In the time that it takes for him to go up Gravity to affect him and for him to come down and touch the ground Then we should probably do a blend tree because that makes sure that all those Frames of our spreadsheet get seen in the time it takes him to jump up and jump down But for this jog animation, I'm just going to do frame by frame animation So I've got it here. Let's call it jog and and Let's Create that jog animation and we'll put it in our animations folder and then from within our jog spreadsheet I'm just going to drag all of these frames into the timeline and Unity recognizes that That's going to be a timeline animation. So it just puts me in one after the other and We can check this out and see if it's what we want it to do So Let's just change this to a free aspect so we can see the whole thing here So if I hit this play button, you can see I'm running. He's going way too fast And that is because this sample is here. So it's essentially just saying this is set at 60 But this is like a 60 frames per second animation and we don't want it to go that fast They're gonna be a little blockier and I'm okay with that So now if we play it, you see we've got a pretty smooth animation It looks like you kind of bucks back a little bit when you run so I could adjust that later, but Let's just for now stick with that and So that's gonna be our jog animation Now what I want to do is make a transition from any state to jog But I need some conditions and The conditions I've kind of set up in conjunction with all my other animations The best one to look at is this walk animation So the conditions are that speed be greater than point zero one So basically the character has to be moving somewhere and that This variable I've created ground is true meaning characters touching the ground if he's jumping We obviously don't want him to be jogging I'm gonna be jumping if he's off the ground so Now that I'm going to be putting this jog animation in place I'm gonna need another Parameter and we're just gonna call it is jogging so Delete this for now actually Let's create that so here's our list of parameters over here and Is jogging is a true or false statement, so We're gonna make it a Boolean Is jogging so we've got it now and now if we go back to this Walk animation Is jogging has to equal false for him to be walking otherwise he's going to be jogging So we want that same list of conditions for the jog animations But is jogging has to be true speed is greater than point zero one ground equals true and Is jogging equals true When all those things are met character should jog Right so In order to set this is jogging variable I need to go into my script here and I'm gonna go into my update function and just add those conditions I've written them before so I'm just pasting them in but basically we're saying if grounded and Input dot get key down Equals key code left shift. I'm gonna make it left shift and should probably set variable for the run button for the jog button in case people in our game wanted to reconfigure that Key or they had a gamepad or something like that, but for now just gonna say key code left shift If it's down Set Boolean is jogging to true If the key goes up Set is jogging to false. All right So now that that's in there Let's test it out Okay, so I'm holding my shift key and you can see this guy is freaking out So what's going on? Let's take a look. Well, it has to do with this Thing which I don't fully understand to be honest But I'm gonna set the transition duration to zero set the offset to zero so it can transition to self Off because obviously we just want it to run its course while the button is down and that should fix that and You can see We've got a jogging animation and again, I mentioned that You know, it looks like he's just sort of bucking backwards a little bit So I'd want to go in there and tweak that but for the most part. We've got a jogging animation I'd also probably want to speed the character up while he's jogging Otherwise, he's just doing that thing that people do when they pretend to run across the street But anyway, that is my workflow for creating a sprite and implementing it in unity


Welcome to the second part of Lecture 18. Now we dive into authentication authorization and there are many different ways to do that, so we just look at some common ones, discuss them a bit, but of course this is a topic that if you really want to build this into a productive website, productive backend, you need to spend quite some time and effort to get this right, since the whole purpose is to keep people from doing what they're not supposed to do. Now we start off with HTTP basic, that's a basic user and password authentication. Whenever you send a request to the server, you send your user and your password via the HTTP headers, so there is a header, a standard HTTP header that is called authorization and you just add the information there. So let's assume we make a request to our server and the regular request will not be successful because the server expects that we use basic authentication, so what you do is you add the authorization header saying basic, so that's the basic method and then there is a string here and that's our user and password. Now this looks pretty encrypted but it's important to make clear that it's not, this is actually just an encoding, so this is just a way to get the user and password down to one string and you can inverse this, so just because this looks very cryptic, doesn't make it safe or secure anyhow, so if I just take this text string, I find a base64 decoder and I say please decode this string, then you'll see it says grisha, cologne, my super secret password, so it's just a decoding, there's nothing secret here. So that's how you use it and on the server side you would check does this header exist, if it exists, is it the right authentication method? If it is, then use base64 to get the actual text string and check whether the user and password are correct, so that's really all you do and then if that's the case you send a proper response, otherwise you say no, probably 401 or 403, forbidden, not authenticated, you are not allowed to use this. All of it is of course sent in clear text, so there's nothing secret here. One issue here is that in every single request you have to send your user and your password and the chance is just very high that over time someone might intercept one of your requests, might read one of your requests and then they have your user credentials, so they can always use it in the future unless you change your password and this is of course a problem because passwords are very often reused and can also be guessed, so you can just try maybe different applications, does the same password work if I try to log into Gmail or anything else, so that's a problem. So what is used instead often is to say the first time you send the request you have to send your user and password, the server checks it and then the server sends you back some token, some kind of field, some kind of string that you use from then on, so you don't have to send your user and your password, so those are token based authentication methods and we'll introduce them later on. Now I'll just quickly give you an example how this works implemented on the server side, so if we go into Express and this is something that I'll upload, this is the material upload, there is a plugin that's called Express Basic Auth that just builds basic authentication into an express server and it's fairly easy to use that, so you just import the module as I did here and then you just tell Express to use Basic Auth as a middleware, so this is just a regular middleware that checks every request that comes in and it expects a list of user credentials. Here it's just hard coded, so that's not very, first of all it's not flexible, I cannot add or remove users and the other problem is that of course I don't want to have this in my code so in a real system this should come from a database somehow. That's nothing we go into here but you should of course not just hard code the users here, but this is just to demonstrate that this works and after this statement every endpoint I implement will require an authentication, so here I have one endpoint slash I get, this one will only work if I send the credentials, before that I have another endpoint slash front end, if I access this one then there is no authentication required. So let's try that, my native terminal to start with and I have it in my slides, so now this is started, if I go to localhost 3000 slash front end I get this horrible looking application, that works if I go to slash I will not get anything and if you look at the details what I get is a 401, so the server says sorry you are not authorized you're unauthorized you cannot access this, if we want to change that we have to send the user and password and we can do that via postman just to show you in detail how this looks like, so let's say we create a new request we get HTTP localhost 3000 slash, if I send this I'll again get unauthorized now if I add the right header then it will work and postman allows me a shortcut here I can actually go into authorization and then choose basic auth so that's exactly what I want to have and we want admin and super secret I think that's yes that's exactly what I had so if I do this now then I'll get 200 okay welcome so the server has actually checked this and just to make sure I can put another password in and you'll see that I get 401 unauthorized so it actually does check what's in here it does not only check whether or not the header is there so that's basic authentication as discussed it's not ideal because you can steal passwords the chance is much higher so instead you typically have token IDs and one way of implementing them is session IDs the way this works is that first you authenticate yourself so the first request is for example using HTTP basic authentication and then the server sends back a response and says yes you are authenticated you are logged in but additionally the server sets a cookie so it says okay in your client now please set the cookie SID is five and this is now the token this is the ID you will use from now on so the next time the user sends a request there should be an arrow here the next time the user does not send any password a user name the user just sends this cookie back and this is something that happens automatic because of cookies so the cookie is being sent and then the server checks does session number five exist if it does you can also load all the data all the things you have you know about the user or the user has been doing or so so this is one way of doing it five is it's not a very good session ID usually this is some kind of cryptic string so that you cannot guess it because as we discussed in lecture two cookies you can change so we can just change it to six for example and so the server should make sure this is a number that is not guessable just like that this is a stateful implementation because if we go back here you'll see that there is a difference whether I have set the cookie or not so it actually depends on previous requests so we have built a stateful implementation this is a conflict with the rest principle so this will not be restful that's a disadvantage as we discussed the problem with stateful implementations is that debugging for example testing is much much harder the other thing is of course just like the user and password if someone reads your request they can steal your session ID and then they can use it so they can use requests with your session ID and they will be successful that's a problem but usually there are other ways to get around that the other thing is of course if you have if you have very easy session IDs like one two three four five you can guess them very easily and then that's also a security risk the general case that you often see of a session ID is a so-called token so basically we're talking about data about a string that you use instead of the user password credentials and that's really to avoid that credentials are being sent back and forth the most common kind of token that you see in users is the bearer token that just means that anyone who has the token anyone who carries it has access to the API one example of that is PayPal they use bearer tokens most applications that use authentication where you log in Facebook Gmail all the big ones they use bearer tokens so this is by far the most general standard and the way it works is again as before we have some kind of authentication we log in with basic authentication or here PayPal uses OAuth2 we discuss that later but in some way where you send here's my user here's my password please log me in and then you get a token back so you get some kind of string back again this should not be a string that is easy to guess you get this back and then in all your future requests for example when you want to make a payment you say authorization instead of basic this time you say bearer and then you just put this token in there so you have a string that you use to log in we can look at that again in postman because I had this I showed PayPal at some point we'll just see whether I still find it PayPal token this is actually the request where I get my token so somewhere in the body here is my authorization information and I will not show that to you but when I send I say okay I'm this user and then I get something back so I'll get something back here's my access token that's the string that I can use so as you see this is very cryptic this is hard to guess that's essentially my my token that I now use to say I am allowed to do something in case someone tries to copy this I will of course make sure that the token is not valid anymore when you are watching this video so don't try it's not working and now the next time when I for example say get payments I actually send this token to the server so this is just a placeholder in postman but basically I say bearer and I put the text string in there that I want to use so that's what I'll do and then the server will say yes or no it worked so most likely this is because I have used the token if I remove this then I think it says unauthorized exactly so here's my authorization information that I'm using now and now if someone listens to my request if someone copies this they get the token but they don't know my password so they only have the token and that's a very good thing because there are a couple of sort of safety measures built into the tokens the first one is tokens typically expire so they have a certain validity for example a couple of hours and then they are deleted on the server so if someone gets my request they can copy the token but they can only use it for a couple of hours and then it's gone and then they cannot get a new token unless they listen to my connection again the other thing is tokens usually have a scope so on your API you can implement this in a way that one token is only valid for example for payments and nothing else and then if someone steals it that's bad but they can still only access the payment they might not be able to do other things so it's not like they directly get full access to your account so that's some kind of safety built into the token system so these are tokens that there are just in case you're interested there are lots of different token implementations so for example there's one that is fairly popular that is called a json web token jwt in case you have seen that so it's just different ways of generating of representing these kind of text strings okay we still have this already the first authentication so in the beginning you have to send the user in a password and we discussed that the HTTP basic authentication is not that safe because it's clear text and it's easy to actually get this wrong in your server implementation so there is something called OAuth 2 which is sort of the industry standard of doing this and the principle is you delegate the authentication to someone that has sort of has the resources has to know how to implement this in a good way and that's exactly what you have on all the websites that say hey you can sign into this with google or you can sign in with github or anything else this is basically OAuth 2 so you say someone else should handle the authentication they then tell you yes the user is the person he or she is saying and then they can use your application there are a lot of different access scenarios in OAuth 2 so if you're interested there is a whole lot to read up I'll just show you at the most I'll just show you the most basic one and the most common one so there are others the way this works is you have an application so this is your application you are writing in this case we use gitlab so assume we are writing gitlab we are the gitlab developers there is some kind of API like a restful API that the user wants to get access to and you have to handle authentication so make sure that only the right people get access to the right resources and then we have an authorization server so we use some kind of industry standard some company that has implemented this and this works then as follows I say I want to go to gitlab.com I want to use the API and I say please log me in with google gitlab then redirects me to a special google url where I have to enter my user and password you all know this right if I click sign in with google I come to google gmail looking page and I have to enter my gmail account and password if this is successful then the authorization server will connect to gitlab so it will actually send the token we have discussed to gitlab before and then if this is successful your original your original request will get the response with the token so we'll say here is your token this has worked so this basically means google is handling the authentication gitlab only gets a token it does not get any of our information gitlab never gets to see our user or our password so they don't need to worry about it they don't need to check in their database whether the password is correct that's all handled by google and then we get a token back and then we can actually make a request to the gitlab api with that token and gitlab then only checks whether the token we are sending is the same that they got from google originally that's all they do uh so that's oauth it's a fairly nice thing and it's very standard as you know most websites have something like this nowadays if you're interested there are lots of libraries for example for uh for note so if you just search for oauth note then you'll find all different here's for example an overview on the original oauth page what kind of libraries are there for client and server to implement this uh just so you're aware of this it's not always very easy to implement that so it might even with a library it might take you some time to get this running okay um so this is what we do this is i would say the industry standard uh you have you start off with an oauth to authorization you get a token uh and then you use this bearer token to authorize yourself in the api so that's how many applications nowadays work uh the all the big websites with login are operating based on this there are however still some issues we have um and one of them is all kinds of credentials can be stolen everything whether it's user password whether it's a token a session id or oauth to access token which is just another form of a token so there's nothing different here all of this can somehow be stolen intercepted and then it can be used so let's say i'm making a request to PayPal i want to do a payment and i say here is my token what could happen is that someone for example in the same network manages to to read my request manages to copy my token uh and now what happens is that that attacker can of course send his or her own requests and just adds uh the stolen token and this will be okay so PayPal will say yeah great thanks Grisha you just transferred half a million to some dodgy account so that's a problem um that will always be a problem because you somehow have to send your information across the internet so one thing again is definitely use HTTPS so that this is not clear text but even so things can be stolen and that's a problem there is one other way of making this a bit safer which is called request signing which we look into now request signing has has specific use cases so it's usually not used for kind of front and client side things it's often used when one server one backend talks to another one and we'll get into why that is the case but what happens is that i have a request i want to send for example i want to do a put request to some url uh with content type jason doesn't matter any kind of request and the server the receiver wants to make sure that this request is really coming from me um and i write amazon here because amazon is one of the big users of this technology um what i have is a so-called secret it's called a secret and not a password because the difference to a password is that the server amazon also knows my secret uh if we talk about usernames and passwords usually always say the server should never save the password in clear text so gmail for example should not know my password they just store it in the in an encrypted version here for the secret it's different amazon and me we both know that my secret is my secret so this is the text string and that's important because amazon needs to use that password as well uh what happens is i take my request i take this string put slash quote slash nelson blah blah blah and i create a hash of it then i send my request i send the put request to the server and i include the hash that i have created um so i send the request and then amazon the server creates the same hash again using my secret and checks whether they are identical uh if they are it means the request i've sent is actually the same that i have hashed here and that means i'm the real sender that might be a bit cryptic so we'll go into details um let's assume we have uh the following request i want to do a post request to slash users content type jason and this is the body uh i want to create a new user called ellis she's 33 and her password is secret uh and now i have this string that is called my secret again in practice this is a very long text stream that i get um and what i do now is i use a hash function to do request signing uh and in this particular case this is just one uh technology called h e m a c uh but what you can do there are generators online there are libraries to do that but you put some kind of string in there uh for example this one and you put a secret key in here my secret and then you choose a algorithm for example chart 256 is one that is supposed to be safe and then i say compute uh and then i get a string what has happened uh what a hash function does it it takes an input here the input is somehow this text somehow combined with the secret key uh and it creates a string that is of a specific length so it doesn't matter how much text i put in here uh now i've just copied and pasted this a lot i will always get a string that has the same length so you see that the length has or it has not changed uh and the important thing is if i put in the same string i will get the same output so if i compute this a hundred times i will always get the same output um this means if i take this string and i put my secret here and i press compute i get a certain string and if amazon does the same thing on their server they will also get the same string if i put anything else in there if i for example say delete then you'll see that this string differs now let's see 0 6 3 7 4 5 uh you'll see that it's somehow different there is a different different value came out uh that's essentially what our hash function is doing so the hash function makes sure the input string is mapped to some kind of fixed length string the same input is always mapped to the same string and different inputs are mapped to different strings that's what we call a perfect hash function if this is really the case so what happens is i take my post request as i've just shown you i take this text string i use my secret i use this h m a c algorithm and i create a hash then i send this request to amazon and i put my hash string into the header i say authorization h m a c here is your string i send it to amazon amazon gets this request so they say okay this is what we get they know my secret so what they do now is they take this request they they remove the authorization so they they take exactly the same values that i took uh put it into the h m a c generator and they get a text string out and what they now do is they compare what i have sent them to what they just generate it um if they are the same they accept the request if they are different they decline it uh and this means that you can only send exactly the same request otherwise the hash function will produce a different result and it will say no so if for example i'm an evil attacker now and i send post users but i put my own body in there i changed the the username i changed the age i changed the password uh but since i don't know the secret code i cannot regenerate this hash so i just sent the same value if now amazon takes this generates the hash function it will get a different text string and then if they compare the two they will say okay they are not the same so we actually decline the request um the impact of this is if you listen to my request if anyone intercepts this request um what they can do is they can do a so-called replay attack they can tell they can send exactly the same request again and it will work but if they anyhow change the request if they change the method if they change the url if they change the body then the request will be declined because the authorization is wrong so you have made sure that by signing you have created uh basically a unique request that cannot be changed so what you can do is you can send the same request again that's called a replay attack you basically replay the request but you can never change it so the user the the attacker can only do exactly the same thing that you did the attacker cannot do anything else um and that's really a good thing so basically it can only be sent again it cannot change one thing we can do to it to make this even harder is if we in our hashing function also include the current date then the server can also make sure that we can only replay this within a certain time so we can for example say each request is only allowed to uh be accepted within five minutes uh and then the attacker has to send the same request within five minutes uh otherwise the server will say no uh the disadvantage every kind of method has a disadvantage a disadvantage we have here is that both parties have to have the same secret the same text string and that somehow needs to be exchanged and now this exchange is again a potential attack point because someone can uh intercept this for example if amazon says here is your secret text string someone might be able to read that and then it's the same as a password they can just use it uh what what companies like amazon try to do to avoid this is that they change it over another channel so instead of using uh the same HTTP request response they send you the secret in an email for example uh or on a different website or so and then it's much harder for the for the attacker to both check your email and listen to your HTTP connection or so um the other problem which is not in here is that uh you have to enter this secret somewhere because you get it for example in an email uh and that's why we often don't use this in front end applications because it's a very long text string it's not like a password that you can remember so it's often used when you for example from one back end you use an API in another back end uh then we use these technologies they're not very often used for kind of end user things uh as already discussed amazon aws uses this technique to make sure that uh you are allowed to use uh their API again there are some libraries for this uh not much you probably have to implement this yourself so there are libraries for hmac generation so the how to compute this value uh but the check on the server side whether this is the correct stuff is something you need to implement there are some basic applications on on github so this is uh the conclusion of lecture 18 there are lots of attack surfaces we can we can use an attacker can use to mess with us they can look at the network they can try to listen to our request they can exploit our applications if we have bugs if we have vulnerabilities and finally they can try to get through the user to somehow for example get their password once again a reminder that htdp is completely unencrypted so you should not use this uh use always htds and finally do not assume that just because you use htds you are safe so there are always issues there uh governments spying on you bugs in ssl for example so there are lots of options uh so on top of that you should try to use an authentication method that is somehow secure uh i've shown you some of them all have their tradeoffs so htdp basic is for example is very easy is very quick but you send your password in every request so that's maybe not the best thing uh one thing that you should be doing is rely on well tested libraries and authentication delegations so for example use oauth to zero if you can use libraries that have a lot of users that have for example either a lot of stars on github or lots of downloads on nodejs so that you can make sure that these things are tested uh it's not something that some dude in his basement wrote on a weekend so make sure these things are properly tested and used and that's it for lecture 18 in the next lecture we actually then go into the problems we might be having security vulnerabilities attacks some remarks in detail on nodejs but we'll look at kind of the top vulnerabilities we see in applications so thank you for listening and see you in lecture 19


Hello everyone. Welcome to another live video. I'm just walking through a botanical garden right now up in the highlands about 3,500 feet above sea level. I don't know how I'm able to get a signal up here but somehow I can. So let's make the most of it. Lots of really cool plants here, some that I've never seen before. I just came from the Japanese garden as well. I won't be able to show you that in this video but you can check it out on my Instagram. I'll be posting pictures and videos very soon. So yeah my Instagram is Narc Survival YouTube. Definitely follow me on there if you haven't yet. All right so let's get into the topic for today's video. I have done many videos on this topic already but in this one maybe we can go a bit deeper into it and you know really discuss the mechanics behind it. More of the psychological aspect because of course there are reasons why they behave in that way and why they tend to oppose you so quickly. I mean you know in a normal healthy relationship yes there may be times where you may hate the other person, you may hate your partner. Yes that's normal of course. Sometimes people do things that irritate us, gets under our skin but in a normal healthy relationship it's not that those things don't happen although they may not happen to such an extreme. The difference is that we know how to resolve it. We know how to come to a resolution in mutual agreement and that's really the difference. I love these. I think they're called lobster claws. The first time I saw these was in Sri Lanka. I don't know what it is it's just something about them. Maybe the colour and the shapes. I really like this one. It almost doesn't look real but yeah that's really the difference is that you know we know how to come to a resolution a mutual agreement that's really the difference because instead of getting all emotional you know how to come at it with logic and reasoning and that's really what separates us but these types of people what they do is they get all emotional they get in their feelings it's something about you that just strikes them and makes them turn against you but it's not so much about you and that's that's the assumption that many people make and they get it wrong. They think that if they're turning against you and they hate you then there must be something wrong with you but that's actually not how it is at all.  It's it's a reflection and that that's the reason why you could have two people and they both have the same experience of a situation but they give it a different meaning they get a different take out of it. Now how is that possible? The reason why that's possible is because it's determined by the the meaning that you personally give to it based on your own prior experiences and as you know that people who have this disorder well their prior experiences are based on trauma it's based on childhood trauma conflict that's all they've known in their family dynamic so how can they possibly resolve anything with you if that's all they've ever known they've never known how to choose love over hate no one ever showed them love so you try to bring that to them it's not going to make any sense they can't comprehend it and that's why they're always trying to provoke a reaction out of you because that's the one thing they do understand is your anger and frustration your hatred towards them yeah they know that more than anything else so that's why they're always trying to provoke you they're always trying to make you feel some type of way I mean you know that's why I mean for a start they don't have any love to give you anyway I mean you have to have love within your heart to give it to another person but on top of that it's also if they give you love what are they gonna get out of that they're just looking at it like okay so let's say you know they do have love somehow you know just as an example let's say they did give you that love what would that do for them they just look at it like what so I give this to you just to make you feel good well I'm still miserable it just doesn't work for them in any way it doesn't benefit them but when they hate you and you know they share that hate with you they make you feel hate as well when they do that then it's negative attention it gives them supply and you know now you're speaking their language because that's how they communicate they communicate through low vibrational emotions negative frequencies that's their ideal form of communication so of course they want you to talk the way they talk they want you to speak their language so they they have to teach you they groom you they prepare you for that purpose and that's why by the time you're done with them after everything they've done to you after they've cheated on you they've lied to you they've steal from you you're gonna have nothing but hate in your heart and now you're talking their language and then they steal your qualities and they take that on to someone else but really it's just a mirror reflection they can't really take it from you it's just it's an illusion but they will portray the image of what you want to see it's all about just making you feel how they feel but when it all comes down to it I mean you have to remember that they are very selfish they're self-absorbed and they lack empathy they can't share your experience really they can't really put themselves in your shoes so they don't even know you and you didn't even know who they are I mean when it all comes down to it you realize you never even knew who that person was because they're a completely different person from the one you met in the beginning but yeah yeah they never really learned you they never took the time to get to know you in the beginning it was just this ideal image of you in their minds they took a mental snapshot of what you were supposed to be for them and when you didn't live up to those expectations they devalued you and yeah they never really knew who you are so how can they hate you I mean when you look at it this ideal image that they give to you in the beginning is just a projection of their idealized false self and then as time goes on and they begin to devalue you that is just a projection of everything they hate about them about themselves so it's never really you they hate themselves that's what it comes down to when you really look at it because they don't even know who you are all they do is just project their insecurities onto you but it has nothing to do with you so yeah I mean to put this into a relatively short video this is the reason why they hate you or you know depending on how you're looking at it because really it's just they hate themselves I mean you could look at it as though you didn't live up to the idealized image they had of you well must fall down and yeah that's why they could end up resenting you but then it's also because you know nothing's new and fresh as it was in the beginning so you no longer excited about them you're not giving them supply and they feel entitled to that so yeah that's when they feel like you know you owe that to me you should be validating the image supporting the illusion and when you're not doing that they become resentful because you know they can't acknowledge that something could be wrong with them and how they're perceiving things about you so all they can really do is direct it at you I would go as far as to say that for anyone if you spend enough time around them eventually they will turn against you because they're very insecure I mean that's really the only thing they know how to do so yeah I mean but that you know that's why people who don't really know them and you know maybe they see them just in the day it could be at work especially if it's just a part-time job they're never going to get to know who they really are and the the narcissist is never going to hate them because they have enough time to maintain their false image around them so yeah they can just wait until they go home and then take it out on you but if you spend enough time around them and that's why we say like the primary source of supply you will start to see who they really are it might take a few weeks maybe a few months in some cases depending on if you're spending every day together or maybe it's just once a week then it would take longer but eventually you're gonna start to see it savvy sibling just dropped a big one there in the live chat our narcissist born that way or are they created now that is the ultimate question I mean there are there are psychologists therapists youtubers all who argue over that and personally I would say both I would say that it's more rare for someone to be born genetically as a narcissist or psychopath I would say that most of them learn it because what it really is is just it's a response to trauma but it's really no different to what we experience we when we're involved with narcissists we experience CPTSD complex post-traumatic stress disorder and we may have a stress response we may feel that we are becoming narcissistic what we only care about ourselves and our needs we're just trying to survive we may even lack empathy we put ourselves first we get irritated very easily just like a narcissist right but the difference is for them it happened in their childhood when they were still developing their brains were still like mold so if you imagine they weren't fully solidified so to speak so that's why it's becoming grained in them and it can't change I mean it's like trying to think of an example I mean if you if you have like a liquid and you put it in the freezer and it solidifies you know it's never going to go back exactly exactly the ways it was before it's it's going to be different because it's solidified it can't change its form and well that's not really a good example but I mean it it's fixed in them to where it can't go back it's like a rubber band you can stretch it but it always goes back to its original shape I mean that's not to say that you can't change your personality you can anyone can choose to do that at any moment but it's different for them because to be able to do that you have to go within and self reflect but they don't do that instead they build a fake persona on the surface and that's why when you hurt them you know when when they receive a slight or criticism causes an injury and then for like a brief window they do reflect on maybe who they actually are deep down or it's the void I mean it gets very deep some people say that there is someone in there it's a scared little child who's doing everything they can to survive other people say it's just a dark empty void nothing there I mean it's hard to say I personally believe that it can change from moment to moment in one moment that scared little child and then other times it's like the parent steps in to protect them and then sometimes there's just nothing there but it changes from moment to moment I mean it's really complex I mean these are things that doctors have spent their entire lives trying to explain and I'm just delivering it to you from a few years of my research so you know even for me it is very difficult for me to comprehend it but I think I am on the lines of what it is and what happens you know whether they're born or created I would say most of them it's learned it's a learned behavior it's a response to trauma in their childhood you can see a bit for the trees they're very high up gonna head back down now but yeah you haven't been to many gardens for a while especially where I've done a video so I thought it was good to share that with you I'm just going to head back down this hill now back to the car any other questions please let me know now I will give you my response I am 3,500 feet above sea level so maybe I'm close to the heavens now maybe they can deliver me some you know like a download of high vibrations that I can share with you right now so yeah leave your questions down below I'll give you a response I'll read them out now Jars creation says I tried to go for bad but I couldn't do it because I'm connected to God so it definitely is a choice that's the thing I mean as I was saying I think for some people it is a choice yes well technically for everyone but for them it's more difficult because what you have to remember is they experienced the trauma when they were children so you know as I said it's like solidified it's ingrained you know it's um most of the time it's a learned behavior it's something that was taught to them and it's become fixed because it happens so early in life I mean for us if you experience that later in life it's not going to affect you as much because your inherent values and principles are different you know you've already learned a different way and it's like the rubber band you always go back as you're saying so I think that's important to note and yeah it's a limited choice if anything I mean one thing we all have in common is that we follow the path of least resistance and not only that we tend to follow pleasure over pain you know that's one thing that we all have in common so that's actually what they're doing when you think about it they are choosing the path of least resistance they are just doing what makes them feel good even though we may not see it that way because you know we we've learned different values from that but yeah I mean you know that's why it's so hard for them to change because it's um there's no resistance to it I mean they've already been shown they've learned it and for them it feels good they like how it works so you have to think like why would you change something that you like doesn't make any sense and that's the problem they have to be in a crisis they have to experience suffering and only then they're going to think oh shit I have to change because at that point it's affecting them more than it's affecting anyone else thank you for the donation no matter I really appreciate it how do you get over the fact they are giving the new supply everything you wanted out of them they look so much happier well as some of you know I had to deal with that recently and I'm telling you you just got to remember you know when they were with you you know remember all of that bullshit they give to you and only that that they display to other people as well and that's how you know for a fact that nothing has changed they're still the same they're always going to be that way it's never going to be any different because if it was it would have been that way with you you know you have to think why does someone have to move on to a new relationship to then suddenly change everything about themselves it doesn't work that way they are still the same I don't care what you're seeing I don't care what they're telling you what you're seeing on social media it doesn't matter they were doing that when they when they were with you they were posting up all of their stuff and they were trying to make their ex jealous and then after a while you learned that they were full of shit you learned it was all fake and trust me they are doing that again don't fall for it it's all part of the the cycle it's meant to hurt you because they're so full of hate and resentment I mean that's really what separates them from the rest of us but like I said that hate is more towards themselves I don't want you to identify with that but I know that that's what some of you are going to do I mean you know you taking it so you know there's something wrong with you if they are to leave and find someone else I know that's what you're thinking and I get that and I've experienced that myself many times of course but I'm telling you that it isn't real just as when they were with you they made it seem to everyone to your family and friends everything was so perfect but deep down you knew what was going on behind closed doors you were getting all of it and that's exactly what they're doing it's just that this time you're seeing it from the outside so you're looking at it like everything's perfect you're seeing all the trips they're taking on Instagram and so that's that's why you're seeing it that way just as other people were seeing that way when you were with them and that's how you got to look at it it's an orchestration so don't let it get you down it isn't real just as it wasn't real with you but thank you for the donation I appreciate it and I hope that my advice helps you McDonald yes great response by valuing yourself if there's one thing that we need to do is value ourselves more whenever you end up with someone who doesn't value you the reason why that happens is because you don't value yourself because otherwise you would expect them to value you I mean that would be a primary condition of anyone being around you I mean you've got to think why would you want someone around you who doesn't value you unless you don't value yourself so you know if you want to attract the right types of people into your life the way you do that is by valuing yourself as it's been said in the live chat I completely agree with that you know that is the number one thing that you need to do value yourself practice self love then you will find other people of like kind other people who also value themselves other people who also love themselves because they've done the work to get to that point so yeah I mean that's really that's the number one thing that will protect you from these types of people people who don't value you people who treat you like crap I mean some of you may not want to hear it but this is the truth it does start with you it's not victim blaming it's taking personal responsibility for ourselves and the situations that we find ourselves in really it does all start with us because the truth is if we really value ourselves enough we would never let people around that around us like that in the first place so you know that is really the number one thing that we all need to do we all need to value ourselves love ourselves that should be number one and when you do that you have more value and love to give to other people so that isn't selfish that's actually the most selfless thing you can do so I just want to put that out there and now I'm gonna head down this hill so yeah I'd just like to thank you all for joining me on this very deep all of your comments really giving me something to expand on and hit home about at the end there so that was really good a really nice collaboration between me and the viewers Samantha Gonzalez thank you for the donation she asked what's the best approach to begin healing from the trauma bond and managing the obsessive thoughts that is a very complex question especially for the end of the video um you know for anything that involves healing especially things to do with the trauma bond this is um it requires a lot of time to really go into that and I would recommend speaking to a qualified counselor I mean I know I brush on the trauma bond sometimes in my videos but I don't go too deep into it you know I have to stay in my own lane you know I know my place and you know what I can deliver to you and you know that kind of thing it's meant for qualified counselor and I can refer you to a service that I have used and they also sponsor our channel as well so it helps to support the community if you do work with them and yeah I've used them myself and they're very good so that service is better help it's betterhelp.com slash narc survivor and yeah I'm sure if if you book a session with a qualified counselor on there the number one online counseling service on the web they will be able to help you with healing from the trauma bond because it is it's not easy it does take time it's a difficult process but definitely with the white help all of you can do it so I know that may not be the answer you you were looking for but I hope that I have directed you to the right place where you can get the answers you need so yeah that's all for this video 36 minutes gone really deep into it today hope it's been helpful for you and yeah I look forward to speaking with you in another one very soon I really enjoyed it today walking to the gardens with you and yeah it was just a great experience thank you all and have a good day


Let's say you're trying to lose 20 pounds or boost your immunity or increase your ability to fight COVID or even cancer. Well, the amazing thing is with the right diet, you are well on your way to achieving these vital health goals. Welcome to the Nutrition Facts Podcast. I'm your host, Dr. Michael Greger. Today we look at how losing weight without rearranging your gastrointestinal anatomy carries advantages beyond just the lack of surgical risk. The surgical community objects to the characterization of bariatric surgery as merely internal jaw wiring and cutting into healthy organs just to discipline people's behavior. They've gone as far as to rename it metabolic surgery, suggesting the anatomical rearrangements cause changes in digestive hormones that offer unique physiological benefits. As evidence, they point to the remarkable remission rates for type 2 diabetes. After bariatric surgery, about 50% of obese diabetics and 75% of super obese diabetics go into remission, meaning they have normal blood sugars on a regular diet off all diabetes medications. The normalization of blood sugars can happen within literally days after the surgery. And then 15 years after the surgery, 30% may remain free from their diabetes compared to a 7% curate in a non-surgical control group. Are we sure it was the surgery though? One of the most challenging parts of bariatric surgery is lifting the liver. Since obese individuals tend to have such large fatty livers, this can be tricky risking liver injury and bleeding. And large livers are one of the most common reasons less invasive laparoscopic surgery turns into fully invasive open surgery, leaving the patient with a large full belly scar and increased risk of wound infections, complications, and recovery time. But lose even just 5% of your body weight and your fatty liver may shrink by 10%. That's why those awaiting bariatric surgery are put on a diet. Then after surgery, patients are typically placed on an extremely low-calorie liquid diet for weeks. Could their improvement in blood sugars just be from the calorie restriction? Rather than some sort of surgical metabolic magic, researchers decided to put it to the test. At a bariatric surgery clinic at the University of Texas, patients with type 2 diabetes scheduled for gastric bypass volunteered to first undergo an identical period of calorie restriction, but without the surgery. They were placed in the hospital and put on the same diet they would be on immediately before and after the surgery for 10 days, averaging less than 500 calories a day to mimic the surgical situation. Then the researchers weighed it a few months so the patients would gain the weight back and then put them through the actual surgery, matched day-to-day for the diets they were on before. So same patients, same diets, just with or without the actual surgery. If there was some sort of metabolic benefit to the anatomical rearrangement, they would have done better after the actual surgery. But in some ways, they actually did worse. The calorie restriction alone resulted in similar improvements in blood sugar, pancreatic function, and insulin sensitivity, but several measures of diabetic control improved significantly more without the surgery. So the surgery seemed to put them at a metabolic disadvantage. The calorie restriction works by first mobilizing fat out of the liver. Type 2 diabetes is thought to be caused by fat building up in the liver and then spilling over into the pancreas. Everyone may have a personal fat threshold for the safe storage of excess fat. When that limit is exceeded, fat gets deposited into the liver, where it causes insulin resistance.  By the time diabetes is diagnosed, half of our insulin-producing cells may have been destroyed. Put people on a low-calorie diet, though, and the entire process can be reversed. A large enough negative calorie balance can cause a profound drop in liver fat, sufficient to resurrect liver insulin sensitivity within seven days.  Once you drop below your personal fat threshold, you should then be able to resume normal intake and still keep your diabetes at bay. The bottom line is that type 2 diabetes is reversible with weight loss if you catch it early enough. Lose more than 30 pounds, and nearly 90% of those who've had type 2 diabetes for less than four years can achieve remission, whereas it may only be reversible in 50% of those who've lived with the disease for longer than eight years. That's losing weight with diet alone, though. The remission numbers for diabetics losing even more than twice as much weight with bariatric surgery may only be around 75% up to eight years and 40% after that. Losing weight without resorting to surgery may offer other benefits as well. Diabetics losing weight with diet alone can significantly improve markers of systemic inflammation, such as tumor intracrosis factor, whereas levels significantly worsened when about the same amount of weight was lost from a gastric bypass. What about diabetic complications? One of the reasons we don't want diabetes is we don't want to go blind and we don't want to have to go on dialysis. Reversing diabetes with bariatric surgery can improve kidney function, but surprisingly it may not prevent the appearance or progression of diabetic vision loss. Perhaps because bariatric surgery affects diet quantity, but not necessarily diet quality. This reminds me of a famous study published in the New England Journal of Medicine that randomized thousands of diabetics to an intensive lifestyle program that focused on weight loss. Ten years in, the study was stopped prematurely because the diabetics weren't living any longer or having any fewer heart attacks. This may be because they remain on the same heart-clogging diet, but just in smaller portions. In our next story, we look at how weight regain after bariatric surgery can have devastating psychological effects. How sustainable is the weight loss from bariatric surgery? Most gastric bypass patients end up regaining some of the fat they lose over the first year or two after surgery, but five years later, three quarters maintain at least a 20% weight loss. The typical trajectory for someone who starts out obese at 285 pounds, for example, would be to drop to an overweight 178 pounds two years after bariatric surgery, but then regain back up to an obese 207 pounds. This has been chalked up to grazing behavior where compulsive eaters may shift from binging, which becomes more difficult post-surgery, to eating smaller amounts constantly throughout the day. Eight years out, about half of gastric bypass patients continue to describe episodes of disordered eating. As one pediatric obesity specialist described, I have seen many patients who put chocolate bars into a blender with some cream just to pass technically-installed obstacles like a gastric band. Bariatric surgery advertising is filled with happily-ever-after fairy-tale narratives of cherry-picked outcome, offering, as one ad analysis put it, the full Cinderella romance happy ending. This may contribute to the finding that patients often overestimate the amount of weight they'll lose with the procedure and underestimate the difficulty of the recovery process. Surgery forces profound changes in eating habits requiring slow, thoroughly chewed small bites. Your stomach goes from the volume of two soft balls to down to the size of a half a tennis ball in stomach stapling and half of a ping-pong ball in the case of gastric bypass or banding. As you can imagine, weight regain after surgery can have devastating psychological effects as patients may feel they failed their last resort. This may explain why bariatric surgery patients are at a high risk of depression and suicide. Now, severe obesity alone may increase risk of suicidal depression, but even at the same weight, those going through surgery appear to be at higher risk. At the same BMI age and gender, bariatric surgery recipients have nearly four times the odds of suicide compared with counterparts not undergoing the procedure. Most convincingly, before and after mirror image analyses show the risk of serious cell form increases post-surgery among the same individuals. About 150 bariatric surgery patients end up killing themselves or being hospitalized for cell form or attempted suicide. And this only includes confirmed suicides, excluding masked attempts such as overdoses of undetermined intention bariatric surgery patients also have an elevated risk of accidental death, though some of this may be due to changes in alcohol metabolism. Give gastric bypass folks two shots of vodka and because of their altered anatomy, their blood alcohol level shoots past the legal driving limit within minutes. It's unclear whether this plays a role in the 25% increase in prevalence of alcohol problems noted during the second post-operative year. Even those who successfully lose their excess weight and keep it off appear to have a hard time coping. Ten years out, though physical health related quality of life improves, general mental health tends to significantly deteriorate compared to pre-surgical level, even among the biggest losers. Ironically, there's a common notion that bariatric surgery is for cheaters who take the easy way out by choosing the low effort method of weight loss. Shedding the pounds may not shed the stigma of even prior obesity.  There's a strong anti-surgery bias on top of that, such that those who choose the scalpel to lose weight are rated most negatively, for example, being considered less physically attractive. One can imagine how remaining a target of prejudice, even after joining the in-group, could potentially undercut psychological well-being. There can also be unexpected physical consequences of massive weight loss like large hanging flaps of excess skin, beyond being heavy and uncomfortable, and interfering with movement. The skin flap skin result in itching, irritation, dermatitis, and skin infections. Getting a penicillectomy, removing the abdominal apron of hanging skin, can be expensive, and has a complication rate exceeding 50%, with dehiscence, a rupturing of the surgical wound being the most common complication. Even if surgery proves sustainably effective, wrote the founding director of Yale University's Prevention Research Center, the need to rely on the rearrangement of our natural gastrointestinal anatomy as an alternative to better use of feet and forks, diet and exercise seems a societal travesty. In the Middle Ages, starving peasants dreamed of gastronomic utopias, where food just rained down from the sky. The English called it the Kingdom of Cacain. Little could medieval fabulous predict that many of their descendants would not only take permanent residence there, but cut out parts of their stomachs and intestines to combat the abundance. Critics have pointed out the irony of surgically altering healthy organs to make them dysfunctional, malabsorptive on purpose, especially when it comes to operating on children. Bariatric surgery for kids and teens has become widespread, being performed on children as young as five years old. Surgeons defend the practice by arguing that growing up fat can leave emotional scars and quote-unquote lifelong social retardation. Promoters of preventive medicine argue that bariatric surgery is the proverbial ambulance at the bottom of the cliff. In response, proponents of pediatric bariatric surgery have written is often pointed out that we should focus on prevention. Of course, I agree. However, if someone is drowning I don't tell them you should learn how to swim. No, I rescue them. A strong case can be made that the benefits of bariatric surgery far outweigh the risks if the alternative is remaining morbidly obese, which is estimated to shave up to a dozen or more years off of one's life. Although there haven't been any data from randomized trial to back it up yet, compared to non-operated obese individuals, those getting bariatric surgery would be expected to live significantly longer on average. No wonder. Surgeons consistently frame the elective surgery as a life or death necessity. This is a false dichotomy, though. The benefits only outweigh the risks if there are no other alternatives. Might there be a way to lose weight healthfully without resorting to the operating table? That's what my book, How Not to Diet, is all about. We would love it if you could share with us your stories about reinventing your health through evidence-based nutrition. Go to nutritionfacts.org slash testimonials, and we may be able to share it on social media to help inspire others. To see any graphs, charts, graphics, images, or studies mentioned here, please go to the Nutrition Facts podcast landing page. There you'll find all the detailed information you need, plus links to all the sources we cite for each of these topics. For a vital timely text on the pathogens that cause pandemics, you can order the e-book, audio book, or hard copy of my latest book, How to Survive a Pandemic for Recipes. Check out my How Not to Diet Cook book, which is my latest, latest book. It's beautifully designed, with more than 100 recipes for delicious and nutritious meals. And all proceeds I receive from the sales of my books go to charity. NutritionFacts.org is a non-profit, science-based public service where you can sign up for free daily updates on the latest in nutrition research via bite-sized videos and articles. Everything on the website is free. There's no ads, no corporate sponsorship. It's strictly non-commercial, not selling anything. I just put it up as a public service, as a labor of love, as a tribute to my grandmother, whose own life was saved with evidence-based nutrition.